Skip to content

Commit d72bb1e

Browse files
authored
Merge branch 'master' into issue-1454
2 parents 8578b58 + 5d39e62 commit d72bb1e

File tree

17 files changed

+305
-24
lines changed

17 files changed

+305
-24
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.6</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.7-SNAPSHOT</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.7-SNAPSHOT</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.7-SNAPSHOT</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.7-SNAPSHOT</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.7-SNAPSHOT</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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2827,7 +2827,7 @@ at the moment path passed as string (basePath) from upper components can be both
28272827
schema.setType(type);
28282828
}
28292829
}
2830-
if ("array".equals(schema.getType()) && !(schema instanceof ArraySchema && ((ArraySchema) schema).getItems() != null)) {
2830+
if ("array".equals(schema.getType()) && schema.getItems() == null) {
28312831
result.missing(location, "items");
28322832
}
28332833
}

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public ResolverFully(boolean aggregateCombinators) {
5656
private Map<String, Link> links;
5757
private Map<String, Schema> resolvedProperties = new IdentityHashMap<>();
5858
private Map<String, Callback> callbacks;
59-
59+
6060
public void resolveFully(OpenAPI openAPI) {
6161
Components components = openAPI.getComponents();
6262
if (components != null && components.getRequestBodies() != null) {
@@ -85,7 +85,7 @@ public void resolveFully(OpenAPI openAPI) {
8585
if (headers == null) {
8686
headers = new HashMap<>();
8787
}
88-
}
88+
}
8989

9090
if (components != null && components.getParameters() != null) {
9191
parameters = components.getParameters();
@@ -243,7 +243,7 @@ public Header resolveHeader(Header header){
243243
}
244244
return header;
245245
}
246-
246+
247247
public Link resolveLink(Link link){
248248
RefFormat refFormat = computeRefFormat(link.get$ref());
249249
String $ref = link.get$ref();
@@ -272,7 +272,7 @@ public RequestBody resolveRequestBody(RequestBody requestBody){
272272
}
273273
return requestBody;
274274
}
275-
275+
276276
public Callback resolveCallback(Callback callback){
277277
RefFormat refFormat = computeRefFormat(callback.get$ref());
278278
String $ref = callback.get$ref();
@@ -511,6 +511,12 @@ private void aggregateSchemaCombinators(ComposedSchema sourceSchema, Schema targ
511511
targetSchema.addExtension(key, extensions.get(key));
512512
}
513513
}
514+
if (sourceSchema.getExtensions() != null) {
515+
Map<String, Object> extensions = sourceSchema.getExtensions();
516+
for (String key : extensions.keySet()) {
517+
targetSchema.addExtension(key, sourceSchema.getExtensions().get(key));
518+
}
519+
}
514520
}
515521

516522
if (requiredProperties.size() > 0) {

modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ public void testIssue1780() {
108108

109109
}
110110

111+
@Test
112+
public void testParametersAndResponsesAsNumbers() throws Exception {
113+
ParseOptions options = new ParseOptions();
114+
options.setResolve(true);
115+
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("src/test/resources/parametersAsNumbers/swagger.yaml", null, options);
116+
117+
Assert.assertNotNull(result);
118+
Assert.assertNotNull(result.getOpenAPI());
119+
Assert.assertEquals(result.getOpenAPI().getPaths().get("/api/deal/{dealId}").getGet().getParameters().get(0).getName(), "dealId");
120+
Assert.assertEquals(result.getOpenAPI().getPaths().get("/api/deal/{dealId}").getGet().getResponses().get("200").getDescription(), "Success");
121+
}
122+
111123
@Test
112124
public void testIssue1758() throws Exception{
113125
ParseOptions options = new ParseOptions();

modules/swagger-parser-v3/src/test/resources/issue-1266/issue-1266-resolved.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,42 @@ paths:
2121
data2:
2222
type: string
2323
x-extension-ref: 1
24+
/test/extensions/not/inherited/bothinline:
25+
get:
26+
responses:
27+
"200":
28+
description: "A test failing on the merge of extensions in a allOf, with\
29+
\ same extension defined in referencing and referenced"
30+
content:
31+
application/json:
32+
schema:
33+
required:
34+
- data
35+
properties:
36+
data:
37+
type: string
38+
data2:
39+
type: string
40+
x-extension-ref: 3
41+
/test/extensions/not/inherited/both:
42+
get:
43+
responses:
44+
"200":
45+
description: "A test failing on the merge of extensions in a allOf, with\
46+
\ same extension defined in referencing and referenced"
47+
content:
48+
application/json:
49+
schema:
50+
required:
51+
- data
52+
- gps
53+
type: object
54+
properties:
55+
data:
56+
type: string
57+
gps:
58+
type: string
59+
x-extension-ref: 2
2460
components:
2561
schemas:
2662
ResponseModel:
@@ -31,3 +67,14 @@ components:
3167
data:
3268
type: string
3369
x-extension-ref: 1
70+
ExtendedResponseModel:
71+
required:
72+
- data
73+
- gps
74+
type: object
75+
properties:
76+
data:
77+
type: string
78+
gps:
79+
type: string
80+
x-extension-ref: 2

modules/swagger-parser-v3/src/test/resources/issue-1266/issue-1266.yaml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ components:
1313
properties:
1414
data:
1515
type: "string"
16+
ExtendedResponseModel:
17+
type: object
18+
x-extension-ref: 2
19+
allOf:
20+
- $ref: '#/components/schemas/ResponseModel'
21+
- type: object
22+
required:
23+
- gps
24+
properties:
25+
gps:
26+
type: string
1627

1728
paths:
1829
/test/extensions/not/inherited:
@@ -28,4 +39,28 @@ paths:
2839
- type: "object"
2940
properties:
3041
data2:
31-
type: "string"
42+
type: "string"
43+
/test/extensions/not/inherited/bothinline:
44+
get:
45+
responses:
46+
200:
47+
description: "A test failing on the merge of extensions in a allOf, with same extension defined in referencing and referenced"
48+
content:
49+
application/json:
50+
schema:
51+
allOf:
52+
- $ref: "#/components/schemas/ResponseModel"
53+
- type: "object"
54+
x-extension-ref: 3
55+
properties:
56+
data2:
57+
type: "string"
58+
/test/extensions/not/inherited/both:
59+
get:
60+
responses:
61+
200:
62+
description: "A test failing on the merge of extensions in a allOf, with same extension defined in referencing and referenced"
63+
content:
64+
application/json:
65+
schema:
66+
$ref: "#/components/schemas/ExtendedResponseModel"

0 commit comments

Comments
 (0)