Skip to content

Commit 7e63b67

Browse files
authored
Merge branch 'master' into issue1070
2 parents d1d4719 + 974cd15 commit 7e63b67

File tree

20 files changed

+356
-13
lines changed

20 files changed

+356
-13
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
[![Build Status](https://img.shields.io/jenkins/s/https/jenkins.swagger.io/view/OSS%20-%20Java/job/oss-swagger-parser-v2.svg)](https://jenkins.swagger.io/view/OSS%20-%20Java/job/oss-swagger-parser-v2)
66

7+
[![Build Status](https://jenkins.swagger.io/view/OSS%20-%20Java/job/oss-swagger-parser-v2/badge/icon?subject=jenkins%20build%20-%20java%208)](https://jenkins.swagger.io/view/OSS%20-%20Java/job/oss-swagger-parser-v2/)
8+
9+
[![Build Status](https://jenkins.swagger.io/view/OSS%20-%20Java/job/oss-swagger-parser-v2-java9/badge/icon?subject=jenkins%20build%20-%20java%209)](https://jenkins.swagger.io/view/OSS%20-%20Java/job/oss-swagger-parser-v2-java9/)
10+
711
## Overview
812
This is the Swagger Parser project, which reads OpenAPI definitions into current Java POJOs. It also provides a simple framework to add additional converters from different formats into the Swagger objects, making the entire toolchain available.
913

@@ -103,6 +107,9 @@ You can include this library from Sonatype OSS for SNAPSHOTS, or Maven central f
103107
</dependency>
104108
```
105109

110+
## Security contact
111+
112+
Please disclose any security-related issues or vulnerabilities by emailing [[email protected]](mailto:[email protected]), instead of using the public issue tracker.
106113

107114
License
108115
-------

modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ private List<Server> convert(List<Scheme> schemes, String host, String basePath)
420420
servers.add(server);
421421
}
422422
} else {
423-
if (!"/".equals(baseUrl)) {
423+
if (!StringUtils.startsWith(baseUrl, "/") && !"/".equals(baseUrl)) {
424424
baseUrl = "//" + baseUrl;
425425
}
426426
Server server = new Server();

modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public class V2ConverterTest {
9090
private static final String ISSUE_768_JSON = "issue-786.json";
9191
private static final String ISSUE_820_YAML = "issue-820.yaml";
9292
private static final String ISSUE_1032_YAML = "issue-1032.yaml";
93+
private static final String ISSUE_1113_YAML = "issue-1113.yaml";
9394

9495
private static final String API_BATCH_PATH = "/api/batch/";
9596
private static final String PETS_PATH = "/pets";
@@ -779,6 +780,16 @@ public void testIssue1032() throws Exception {
779780
assertEquals(INTEGER_TYPE, integerSchema.getType());
780781
assertEquals(INT64_FORMAT, integerSchema.getFormat());
781782
}
783+
784+
@Test(description = "OpenAPI v2 converter - converts URL correctly when it begins with forward slash")
785+
public void testIssue1113() throws Exception {
786+
final OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_1113_YAML);
787+
assertNotNull(oas);
788+
assertNotNull(oas.getServers());
789+
assertFalse(oas.getServers().isEmpty());
790+
assertNotNull(oas.getServers().get(0));
791+
assertEquals(oas.getServers().get(0).getUrl(), "/test");
792+
}
782793

783794
private OpenAPI getConvertedOpenAPIFromJsonFile(String file) throws IOException, URISyntaxException {
784795
SwaggerConverter converter = new SwaggerConverter();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
swagger: '2.0'
2+
info:
3+
title: Test for Issue 1113
4+
version: 1.0.0
5+
basePath: /test
6+
paths:
7+
/ping:
8+
get:
9+
summary: test
10+
description: 'test'
11+
operationId: pingOp
12+
responses:
13+
'200':
14+
description: OK

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ParameterProcessor.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,25 @@ public List<Parameter> processParameters(List<Parameter> parameters) {
161161
}
162162

163163
}
164+
else if(parameter.getContent() != null){
165+
Map<String,MediaType> content = parameter.getContent();
166+
for( String mediaName : content.keySet()) {
167+
MediaType mediaType = content.get(mediaName);
168+
if(mediaType.getSchema()!= null) {
169+
schema = mediaType.getSchema();
170+
if (schema != null) {
171+
schemaProcessor.processSchema(schema);
172+
}
173+
}
174+
if(mediaType.getExamples() != null) {
175+
for(Example ex: mediaType.getExamples().values()){
176+
exampleProcessor.processExample(ex);
177+
}
178+
}
179+
}
180+
}
164181
}
165182

166183
return processedPathLevelParameters;
167184
}
168-
}
185+
}

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/PathsProcessor.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ protected void updateLocalRefs(RequestBody body, String pathRef) {
225225
if (mediaType.getSchema() != null) {
226226
updateLocalRefs(mediaType.getSchema(), pathRef);
227227
}
228+
Map<String, Example> examples = content.get(key).getExamples();
229+
if (examples != null) {
230+
for (Example example : examples.values()) {
231+
updateLocalRefs(example, pathRef);
232+
}
233+
}
228234
}
229235
}else if(body.get$ref() != null){
230236

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/RequestBodyProcessor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.swagger.v3.parser.processors;
22

33
import io.swagger.v3.oas.models.OpenAPI;
4+
import io.swagger.v3.oas.models.examples.Example;
45
import io.swagger.v3.oas.models.media.MediaType;
56
import io.swagger.v3.oas.models.media.Schema;
67
import io.swagger.v3.oas.models.parameters.RequestBody;
@@ -18,11 +19,13 @@
1819
public class RequestBodyProcessor {
1920
private final SchemaProcessor schemaProcessor;
2021
private final ExternalRefProcessor externalRefProcessor;
22+
private final ExampleProcessor exampleProcessor;
2123
private final ResolverCache cache;
2224
private final OpenAPI openAPI;
2325

2426
public RequestBodyProcessor(ResolverCache cache, OpenAPI openAPI) {
2527
schemaProcessor = new SchemaProcessor(cache,openAPI);
28+
exampleProcessor = new ExampleProcessor(cache,openAPI);
2629
this.externalRefProcessor = new ExternalRefProcessor(cache, openAPI);
2730
this.cache = cache;
2831
this.openAPI = openAPI;
@@ -44,6 +47,11 @@ public void processRequestBody(RequestBody requestBody) {
4447
schemaProcessor.processSchema(schema);
4548
}
4649
}
50+
if(mediaType.getExamples() != null) {
51+
for(Example ex: mediaType.getExamples().values()){
52+
exampleProcessor.processExample(ex);
53+
}
54+
}
4755
}
4856
}
4957
}

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/DeserializationUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.databind.JsonNode;
44
import io.swagger.v3.core.util.Yaml;
55
import io.swagger.v3.core.util.Json;
6+
import org.yaml.snakeyaml.constructor.SafeConstructor;
67

78
import java.io.IOException;
89

@@ -57,12 +58,12 @@ private static boolean isJson(String contents) {
5758
}
5859

5960
public static JsonNode readYamlTree(String contents) {
60-
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml();
61+
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml(new SafeConstructor());
6162
return Json.mapper().convertValue(yaml.load(contents), JsonNode.class);
6263
}
6364

6465
public static <T> T readYamlValue(String contents, Class<T> expectedType) {
65-
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml();
66+
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml(new SafeConstructor());
6667
return Json.mapper().convertValue(yaml.load(contents), expectedType);
6768
}
6869
}

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,6 +2242,8 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result){
22422242
for (JsonNode n : enumArray) {
22432243
if (n.isNumber()) {
22442244
schema.addEnumItemObject(n.numberValue());
2245+
} else if (n.isBoolean()) {
2246+
schema.addEnumItemObject(n.booleanValue());
22452247
} else if (n.isValueNode()) {
22462248
try {
22472249
schema.addEnumItemObject( getDecodedObject( schema, n.asText(null)));

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/RefUtils.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,17 @@ public static String readExternalRef(String file, RefFormat refFormat, List<Auth
183183
result = readAll(pathToUse);
184184
} else {
185185
String url = file;
186-
if(url.contains("..")) {
187-
url = parentDirectory + url.substring(url.indexOf(".") + 2);
188-
}else{
186+
if (url.contains("..")) {
187+
int parentCount = 0;
188+
while (url.contains("..")) {
189+
url = url.substring(url.indexOf(".") + 2);
190+
parentCount++;
191+
}
192+
for (int i = 0; i < parentCount - 1; i++) {
193+
parentDirectory = parentDirectory.getParent();
194+
}
195+
url = parentDirectory + url;
196+
} else {
189197
url = parentDirectory + url.substring(url.indexOf(".") + 1);
190198
}
191199
final Path pathToUse2 = parentDirectory.resolve(url).normalize();

0 commit comments

Comments
 (0)