Skip to content

Commit

Permalink
Issue 2071. Correctly handle external refs in array items composed sc…
Browse files Browse the repository at this point in the history
…hemas
  • Loading branch information
chimmi authored and frantuma committed Apr 4, 2024
1 parent 6027e73 commit dc8953b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,11 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
ArraySchema arraySchema = (ArraySchema) schema;
if (StringUtils.isNotBlank(arraySchema.getItems().get$ref())) {
processRefSchema(((ArraySchema) schema).getItems(), file);
} else if (arraySchema.getItems() instanceof ComposedSchema) {
ComposedSchema composedSchema = (ComposedSchema) arraySchema.getItems();
processComposedSchema(composedSchema, file);
} else {
if (arraySchema.getItems() instanceof ComposedSchema) {
ComposedSchema composedSchema = (ComposedSchema) arraySchema.getItems();
processComposedSchema(composedSchema, file);
}
processProperties(arraySchema.getItems().getProperties(), file);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,13 @@ public void testHandleComposedSchemasInArrayItems() {
SwaggerParseResult parseResult = openApiParser.readLocation("issue-2071/openapi.yaml", null, options);
OpenAPI openAPI = parseResult.getOpenAPI();

assertEquals(openAPI.getComponents().getSchemas().size(), 3);
assertTrue(openAPI.getComponents().getSchemas().containsKey("Response"));
assertTrue(openAPI.getComponents().getSchemas().containsKey("ProductRow"));
assertTrue(openAPI.getComponents().getSchemas().containsKey("ProductsRowType"));
Map<String, Schema> components = openAPI.getComponents().getSchemas();
assertEquals(components.size(), 5);
assertTrue(components.containsKey("Response"));
assertTrue(components.containsKey("ProductRow"));
assertTrue(components.containsKey("ProductRowType"));
assertTrue(components.containsKey("OrderRow"));
assertTrue(components.containsKey("OrderRowType"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ components:
items:
oneOf:
- $ref: '#/components/schemas/ProductRow'
properties:
orderRow:
$ref: '#/components/schemas/OrderRow'
discriminator:
propertyName: type
mapping:
Expand All @@ -16,10 +19,24 @@ components:
- type
properties:
type:
$ref: '#/components/schemas/ProductsRowType'
$ref: '#/components/schemas/ProductRowType'
payload:
type: string
ProductsRowType:
ProductRowType:
type: string
enum:
- product
OrderRow:
type: object
additionalProperties: false
required:
- type
properties:
type:
$ref: '#/components/schemas/OrderRowType'
payload:
type: string
OrderRowType:
type: string
enum:
- order

0 comments on commit dc8953b

Please sign in to comment.