Skip to content

Commit 77da92e

Browse files
committed
fixing bug when parser trying to solve remote ref in additional properties schema #342
1 parent 0703301 commit 77da92e

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,26 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
111111
}
112112
}
113113
}
114+
if(schema.getAdditionalProperties() != null){
115+
Schema additionalProperty = schema.getAdditionalProperties();
116+
if (additionalProperty.get$ref() != null) {
117+
processRefProperty(additionalProperty, file);
118+
} else if (additionalProperty instanceof ArraySchema) {
119+
ArraySchema arrayProp = (ArraySchema) additionalProperty;
120+
if (arrayProp.getItems().get$ref() != null) {
121+
processRefProperty(arrayProp.getItems(), file);
122+
}
123+
} else if (additionalProperty.getAdditionalProperties() != null) {
124+
Schema mapProp = additionalProperty;
125+
if (mapProp.getAdditionalProperties().get$ref() != null) {
126+
processRefProperty(mapProp.getAdditionalProperties(), file);
127+
} else if (mapProp.getAdditionalProperties() instanceof ArraySchema &&
128+
((ArraySchema) mapProp.getAdditionalProperties()).getItems().get$ref() != null) {
129+
processRefProperty(((ArraySchema) mapProp.getAdditionalProperties()).getItems(), file);
130+
}
131+
}
132+
133+
}
114134
if (schema instanceof ArraySchema && ((ArraySchema) schema).getItems().get$ref() != null) {
115135
processRefProperty(((ArraySchema) schema).getItems(), file);
116136
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,17 @@ public void testInlineModelResolverByUrl(@Injectable final List<AuthorizationVal
303303
assertNotNull(userAddress.getProperties().get("street"));
304304
}
305305

306+
@Test
307+
public void testRefAdditionalProperties() throws Exception {
308+
OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/additionalProperties.yaml");
309+
310+
Assert.assertNotNull(openAPI);
311+
Assert.assertTrue(openAPI.getComponents().getSchemas().size() == 3);
312+
Assert.assertNotNull(openAPI.getComponents().getSchemas().get("link-object"));
313+
Assert.assertNotNull(openAPI.getComponents().getSchemas().get("rel-data"));
314+
Assert.assertNotNull(openAPI.getComponents().getSchemas().get("result"));
315+
}
316+
306317

307318
private static int getDynamicPort() {
308319
return new Random().ints(10000, 20000).findFirst().getAsInt();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
openapi: 3.0.0
3+
servers:
4+
- url: http://swagger.io/show-bug
5+
info:
6+
title: Test API
7+
version: 1.0.0
8+
paths:
9+
"/tests":
10+
get:
11+
operationId: listTests
12+
responses:
13+
'200':
14+
description: Returns results.
15+
content:
16+
application/json:
17+
schema:
18+
"$ref": "./globals.yaml#/components/schemas/result"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
components:
2+
schemas:
3+
link-object:
4+
type: object
5+
additionalProperties:
6+
"$ref": "#/components/schemas/rel-data"
7+
rel-data:
8+
type: object
9+
required:
10+
- href
11+
properties:
12+
href:
13+
type: string
14+
note:
15+
type: string
16+
result:
17+
type: object
18+
properties:
19+
name:
20+
type: string
21+
_links:
22+
"$ref": "#/components/schemas/link-object"

0 commit comments

Comments
 (0)