From 80a3eba9b465e65c12594fb6c925580fcdc82e99 Mon Sep 17 00:00:00 2001 From: chimmi <3124852+chimmi@users.noreply.github.com> Date: Thu, 4 Apr 2024 00:09:21 +0300 Subject: [PATCH] Issue 2071. Correctly handle external refs in array items composed schemas --- .../processors/ExternalRefProcessor.java | 7 ++++--- .../processors/ExternalRefProcessorTest.java | 11 ++++++---- .../resources/issue-2071/definitions.yaml | 21 +++++++++++++++++-- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java index de955cef71..0413f79312 100644 --- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java +++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java @@ -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); } } diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/processors/ExternalRefProcessorTest.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/processors/ExternalRefProcessorTest.java index b83feee3e4..267591ad0c 100644 --- a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/processors/ExternalRefProcessorTest.java +++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/processors/ExternalRefProcessorTest.java @@ -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 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")); } } diff --git a/modules/swagger-parser-v3/src/test/resources/issue-2071/definitions.yaml b/modules/swagger-parser-v3/src/test/resources/issue-2071/definitions.yaml index 25a85f75b5..3d0068dfb0 100644 --- a/modules/swagger-parser-v3/src/test/resources/issue-2071/definitions.yaml +++ b/modules/swagger-parser-v3/src/test/resources/issue-2071/definitions.yaml @@ -5,6 +5,9 @@ components: items: oneOf: - $ref: '#/components/schemas/ProductRow' + properties: + orderRow: + $ref: '#/components/schemas/OrderRow' discriminator: propertyName: type mapping: @@ -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