Skip to content

Commit 6c398fe

Browse files
committed
fix: additional properties external references not processed. Fixes #2218
1 parent fa5279d commit 6c398fe

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
169169
} else if (additionalProperty instanceof ArraySchema) {
170170
ArraySchema arrayProp = (ArraySchema) additionalProperty;
171171
if (arrayProp.getItems() != null && arrayProp.getItems().get$ref() != null &&
172-
StringUtils.isNotBlank(arrayProp.get$ref())) {
172+
StringUtils.isNotBlank(arrayProp.getItems().get$ref())) {
173173
processRefSchema(arrayProp.getItems(), file);
174174
}
175175
} else if (additionalProperty.getAdditionalProperties() != null && additionalProperty.getAdditionalProperties() instanceof Schema) {

modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/processors/ExternalRefProcessorTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import static org.junit.Assert.assertThat;
3030
import static org.junit.Assert.assertTrue;
3131
import static org.testng.Assert.assertEquals;
32+
import static org.testng.Assert.assertNotNull;
3233

3334

3435
public class ExternalRefProcessorTest {
@@ -254,4 +255,22 @@ public void testHandleInlineRefsInComposedSchemas() {
254255
assertThat(anyOfInlineProduct.get$ref(), is("#/components/schemas/Product"));
255256
}
256257

258+
@Test
259+
public void testAdditionalPropertiesReferenceResolution() {
260+
String inputSpec = "src/test/resources/issue-2218/main.yaml";
261+
List<AuthorizationValue> authorizationValues = null;
262+
263+
ParseOptions options = new ParseOptions();
264+
options.setResolve(true);
265+
SwaggerParseResult result = new OpenAPIV3Parser().readLocation(inputSpec, authorizationValues, options);
266+
267+
OpenAPI openAPI = result.getOpenAPI();
268+
269+
Map<String, Schema> schemas = openAPI.getComponents().getSchemas();
270+
assertNotNull(schemas, "Schemas should not be null");
271+
Assert.assertTrue(schemas.containsKey("FlagsOfFlags"), "FlagsOfFlags schema should be resolved and available in components");
272+
Assert.assertTrue(schemas.containsKey("Flags"), "Flags schema should be resolved and available in components");
273+
Assert.assertTrue(schemas.containsKey("Flag"), "Flag schema should be resolved and available in components");
274+
}
275+
257276
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
openapi: 3.0.3
2+
info:
3+
description: A service with remote models
4+
version: 1.0.o
5+
title: A service
6+
paths:
7+
/foo:
8+
get:
9+
description: Get Flag of flags
10+
responses:
11+
'200':
12+
description: ok
13+
content:
14+
application/json:
15+
schema:
16+
$ref: './model.yaml#/components/schemas/FlagsOfFlags'
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
openapi: 3.0.3
2+
info:
3+
description: Description
4+
version: 1.0.0
5+
title: A title
6+
paths: {}
7+
components:
8+
schemas:
9+
Flag:
10+
type: object
11+
description: Active flag
12+
properties:
13+
isActive:
14+
type: boolean
15+
Flags:
16+
type: object
17+
description: Map of flags
18+
additionalProperties:
19+
type: array
20+
items:
21+
$ref: '#/components/schemas/Flag'
22+
FlagsOfFlags:
23+
type: object
24+
description: Flag of flag configuration
25+
additionalProperties:
26+
type: array
27+
items:
28+
$ref: '#/components/schemas/Flags'

0 commit comments

Comments
 (0)