Skip to content

Commit 80a3eba

Browse files
chimmifrantuma
authored andcommitted
Issue 2071. Correctly handle external refs in array items composed schemas
1 parent 96241cb commit 80a3eba

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,11 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
183183
ArraySchema arraySchema = (ArraySchema) schema;
184184
if (StringUtils.isNotBlank(arraySchema.getItems().get$ref())) {
185185
processRefSchema(((ArraySchema) schema).getItems(), file);
186-
} else if (arraySchema.getItems() instanceof ComposedSchema) {
187-
ComposedSchema composedSchema = (ComposedSchema) arraySchema.getItems();
188-
processComposedSchema(composedSchema, file);
189186
} else {
187+
if (arraySchema.getItems() instanceof ComposedSchema) {
188+
ComposedSchema composedSchema = (ComposedSchema) arraySchema.getItems();
189+
processComposedSchema(composedSchema, file);
190+
}
190191
processProperties(arraySchema.getItems().getProperties(), file);
191192
}
192193
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,13 @@ public void testHandleComposedSchemasInArrayItems() {
220220
SwaggerParseResult parseResult = openApiParser.readLocation("issue-2071/openapi.yaml", null, options);
221221
OpenAPI openAPI = parseResult.getOpenAPI();
222222

223-
assertEquals(openAPI.getComponents().getSchemas().size(), 3);
224-
assertTrue(openAPI.getComponents().getSchemas().containsKey("Response"));
225-
assertTrue(openAPI.getComponents().getSchemas().containsKey("ProductRow"));
226-
assertTrue(openAPI.getComponents().getSchemas().containsKey("ProductsRowType"));
223+
Map<String, Schema> components = openAPI.getComponents().getSchemas();
224+
assertEquals(components.size(), 5);
225+
assertTrue(components.containsKey("Response"));
226+
assertTrue(components.containsKey("ProductRow"));
227+
assertTrue(components.containsKey("ProductRowType"));
228+
assertTrue(components.containsKey("OrderRow"));
229+
assertTrue(components.containsKey("OrderRowType"));
227230
}
228231

229232
}

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ components:
55
items:
66
oneOf:
77
- $ref: '#/components/schemas/ProductRow'
8+
properties:
9+
orderRow:
10+
$ref: '#/components/schemas/OrderRow'
811
discriminator:
912
propertyName: type
1013
mapping:
@@ -16,10 +19,24 @@ components:
1619
- type
1720
properties:
1821
type:
19-
$ref: '#/components/schemas/ProductsRowType'
22+
$ref: '#/components/schemas/ProductRowType'
2023
payload:
2124
type: string
22-
ProductsRowType:
25+
ProductRowType:
2326
type: string
2427
enum:
2528
- product
29+
OrderRow:
30+
type: object
31+
additionalProperties: false
32+
required:
33+
- type
34+
properties:
35+
type:
36+
$ref: '#/components/schemas/OrderRowType'
37+
payload:
38+
type: string
39+
OrderRowType:
40+
type: string
41+
enum:
42+
- order

0 commit comments

Comments
 (0)