Skip to content

Commit 608fc7b

Browse files
authored
Merge branch 'master' into master
2 parents 41cc5c1 + 4c74190 commit 608fc7b

File tree

24 files changed

+802
-75
lines changed

24 files changed

+802
-75
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ You can include this library from Sonatype OSS for SNAPSHOTS, or Maven central f
111111
<dependency>
112112
<groupId>io.swagger.parser.v3</groupId>
113113
<artifactId>swagger-parser</artifactId>
114-
<version>2.1.3</version>
114+
<version>2.1.8</version>
115115
</dependency>
116116
```
117117

modules/swagger-parser-cli/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>swagger-parser-project</artifactId>
77
<groupId>io.swagger.parser.v3</groupId>
8-
<version>2.1.4-SNAPSHOT</version>
8+
<version>2.1.8</version>
99
<relativePath>../..</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>
@@ -69,7 +69,7 @@
6969
<dependency>
7070
<groupId>io.swagger.parser.v3</groupId>
7171
<artifactId>swagger-parser-v3</artifactId>
72-
<version>2.1.4-SNAPSHOT</version>
72+
<version>2.1.8</version>
7373
<scope>compile</scope>
7474
</dependency>
7575
<dependency>

modules/swagger-parser-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>io.swagger.parser.v3</groupId>
55
<artifactId>swagger-parser-project</artifactId>
6-
<version>2.1.4-SNAPSHOT</version>
6+
<version>2.1.8</version>
77
<relativePath>../..</relativePath>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>

modules/swagger-parser-v2-converter/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>io.swagger.parser.v3</groupId>
55
<artifactId>swagger-parser-project</artifactId>
6-
<version>2.1.4-SNAPSHOT</version>
6+
<version>2.1.8</version>
77
<relativePath>../..</relativePath>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>

modules/swagger-parser-v3/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>io.swagger.parser.v3</groupId>
55
<artifactId>swagger-parser-project</artifactId>
6-
<version>2.1.4-SNAPSHOT</version>
6+
<version>2.1.8</version>
77
<relativePath>../..</relativePath>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/ResolverCache.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,16 @@ else if (rootPath != null) {
180180
//a definition path is defined, meaning we need to "dig down" through the JSON tree and get the desired entity
181181
String[] jsonPathElements = definitionPath.split("/");
182182
for (String jsonPathElement : jsonPathElements) {
183-
tree = tree.get(unescapePointer(jsonPathElement));
183+
if (tree.isArray()) {
184+
try {
185+
tree = tree.get(Integer.valueOf(jsonPathElement));
186+
} catch (NumberFormatException numberFormatException) {
187+
//
188+
}
189+
} else {
190+
tree = tree.get(unescapePointer(jsonPathElement));
191+
}
192+
184193
//if at any point we do find an element we expect, print and error and abort
185194
if (tree == null) {
186195
throw new RuntimeException("Could not find " + definitionPath + " in contents of " + file);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void processOperation(Operation operation) {
5050

5151
RequestBody requestBody = operation.getRequestBody();
5252
if (requestBody != null) {
53-
// This part allows paser to put requestBody inline without the resolveFully
53+
// This part allows parser to put requestBody inline without the resolveFully
5454
// option set to true
5555
if (requestBody.get$ref() != null && cache != null && cache.getParseOptions() != null && cache.getParseOptions().isResolveRequestBody()) {
5656
requestBodyProcessor.processRequestBody(requestBody);

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/reference/ReferenceUtils.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,17 @@ public static JsonNode jsonPointerEvaluate(String fragment, JsonNode tree, Strin
136136
String[] tokens = fragment.split("/");
137137
JsonNode node = tree;
138138
for (String token : tokens) {
139-
if (StringUtils.isNotBlank(token)) {
139+
if (StringUtils.isBlank(token)) {
140+
continue;
141+
}
142+
if (node.isArray()) {
143+
node = node.get(Integer.valueOf(token));
144+
} else {
140145
node = node.get(ReferenceUtils.unescapePointer(token));
141-
//if at any point we do find an element we expect, print and error and abort
142-
if (node == null) {
143-
throw new RuntimeException("Could not find " + fragment + " in contents of " + uri);
144-
}
146+
}
147+
//if at any point we do find an element we expect, print and error and abort
148+
if (node == null) {
149+
throw new RuntimeException("Could not find " + fragment + " in contents of " + uri);
145150
}
146151
}
147152
return node;

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import io.swagger.v3.oas.models.Operation;
1414
import io.swagger.v3.oas.models.PathItem;
1515
import io.swagger.v3.oas.models.Paths;
16+
import io.swagger.v3.oas.models.SpecVersion;
1617
import io.swagger.v3.oas.models.callbacks.Callback;
1718
import io.swagger.v3.oas.models.examples.Example;
1819
import io.swagger.v3.oas.models.links.Link;
@@ -313,6 +314,7 @@ public OpenAPI parseRoot(JsonNode node, ParseResult result, String path) {
313314
return null;
314315
} else if (value.startsWith("3.1")) {
315316
result.openapi31(true);
317+
openAPI.setSpecVersion(SpecVersion.V31);
316318
}
317319
if (!value.startsWith("3.0.") && !value.startsWith("3.1.")){
318320
result.warning(location, "The provided definition does not specify a valid version field");
@@ -332,6 +334,10 @@ public OpenAPI parseRoot(JsonNode node, ParseResult result, String path) {
332334
openAPI.setComponents(components);
333335
this.components = components;
334336
if(result.validateInternalRefs) {
337+
/* TODO currently only capable of validating if ref is to root schema withing #/components/schemas
338+
* need to evaluate json pointer instead to also allow validation of nested schemas
339+
* e.g. #/components/schemas/foo/properties/bar
340+
*/
335341
for (String schema : localSchemaRefs.keySet()) {
336342
if (components.getSchemas().get(schema) == null) {
337343
result.invalidType(localSchemaRefs.get(schema), schema, "schema", rootNode);
@@ -2763,7 +2769,11 @@ at the moment path passed as string (basePath) from upper components can be both
27632769
} else {
27642770
schema.set$ref(ref.asText());
27652771
}
2766-
if(schema.get$ref().startsWith("#/components/schemas")){// it's internal
2772+
/* TODO currently only capable of validating if ref is to root schema withing #/components/schemas
2773+
* need to evaluate json pointer instead to also allow validation of nested schemas
2774+
* e.g. #/components/schemas/foo/properties/bar
2775+
*/
2776+
if(schema.get$ref().startsWith("#/components/schemas") && StringUtils.countMatches(schema.get$ref(), "/") == 3){
27672777
String refName = schema.get$ref().substring(schema.get$ref().lastIndexOf("/")+1);
27682778
localSchemaRefs.put(refName,location);
27692779
}
@@ -2827,7 +2837,7 @@ at the moment path passed as string (basePath) from upper components can be both
28272837
schema.setType(type);
28282838
}
28292839
}
2830-
if ("array".equals(schema.getType()) && !(schema instanceof ArraySchema && ((ArraySchema) schema).getItems() != null)) {
2840+
if ("array".equals(schema.getType()) && schema.getItems() == null) {
28312841
result.missing(location, "items");
28322842
}
28332843
}

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

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.io.FileInputStream;
1212
import java.io.IOException;
1313
import java.io.InputStream;
14+
import java.net.URL;
1415
import java.nio.file.Files;
1516
import java.nio.file.Path;
1617
import java.util.List;
@@ -150,48 +151,20 @@ public static String readExternalClasspathRef(String file, RefFormat refFormat,
150151
}
151152

152153
public static String buildUrl(String rootPath, String relativePath) {
153-
String[] rootPathParts = rootPath.split("/");
154-
String [] relPathParts = relativePath.split("/");
155-
156-
if(rootPath == null || relativePath == null) {
157-
return null;
158-
}
159-
160-
int trimRoot = 0;
161-
int trimRel = 0;
162-
163-
if(!"".equals(rootPathParts[rootPathParts.length - 1])) {
164-
trimRoot = 1;
165-
}
166-
if("".equals(relPathParts[0])) {
167-
trimRel = 1; trimRoot = rootPathParts.length-3;
168-
}
169-
for(int i = 0; i < rootPathParts.length; i++) {
170-
if("".equals(rootPathParts[i])) {
171-
trimRel += 1;
172-
}
173-
else {
174-
break;
175-
}
176-
}
177-
for(int i = 0; i < relPathParts.length; i ++) {
178-
if(".".equals(relPathParts[i])) {
179-
trimRel += 1;
180-
}
181-
else if ("..".equals(relPathParts[i])) {
182-
trimRel += 1; trimRoot += 1;
183-
}
184-
}
185-
186-
String [] outputParts = new String[rootPathParts.length + relPathParts.length - trimRoot - trimRel];
187-
System.arraycopy(rootPathParts, 0, outputParts, 0, rootPathParts.length - trimRoot);
188-
System.arraycopy(relPathParts,
189-
trimRel,
190-
outputParts,
191-
rootPathParts.length - trimRoot,
192-
relPathParts.length - trimRel);
193-
194-
return StringUtils.join(outputParts, "/");
154+
if(rootPath == null || relativePath == null) {
155+
return null;
156+
}
157+
158+
try {
159+
int until = rootPath.lastIndexOf("/")+1;
160+
String root = rootPath.substring(0, until);
161+
URL rootUrl = new URL(root);
162+
URL finalUrl = new URL(rootUrl, relativePath);
163+
return finalUrl.toString();
164+
}
165+
catch(Exception e) {
166+
throw new RuntimeException(e);
167+
}
195168
}
196169

197170
public static String readExternalRef(String file, RefFormat refFormat, List<AuthorizationValue> auths,

0 commit comments

Comments
 (0)