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 cd00224ce1..af3b6aedbc 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 @@ -169,7 +169,7 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) { } else if (additionalProperty instanceof ArraySchema) { ArraySchema arrayProp = (ArraySchema) additionalProperty; if (arrayProp.getItems() != null && arrayProp.getItems().get$ref() != null && - StringUtils.isNotBlank(arrayProp.get$ref())) { + StringUtils.isNotBlank(arrayProp.getItems().get$ref())) { processRefSchema(arrayProp.getItems(), file); } } else if (additionalProperty.getAdditionalProperties() != null && additionalProperty.getAdditionalProperties() instanceof Schema) { 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 ace17ff003..10c5f6437a 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 @@ -29,6 +29,7 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; public class ExternalRefProcessorTest { @@ -254,4 +255,22 @@ public void testHandleInlineRefsInComposedSchemas() { assertThat(anyOfInlineProduct.get$ref(), is("#/components/schemas/Product")); } + @Test + public void testAdditionalPropertiesReferenceResolution() { + String inputSpec = "src/test/resources/issue-2218/main.yaml"; + List authorizationValues = null; + + ParseOptions options = new ParseOptions(); + options.setResolve(true); + SwaggerParseResult result = new OpenAPIV3Parser().readLocation(inputSpec, authorizationValues, options); + + OpenAPI openAPI = result.getOpenAPI(); + + Map schemas = openAPI.getComponents().getSchemas(); + assertNotNull(schemas, "Schemas should not be null"); + Assert.assertTrue(schemas.containsKey("FlagsOfFlags"), "FlagsOfFlags schema should be resolved and available in components"); + Assert.assertTrue(schemas.containsKey("Flags"), "Flags schema should be resolved and available in components"); + Assert.assertTrue(schemas.containsKey("Flag"), "Flag schema should be resolved and available in components"); + } + } diff --git a/modules/swagger-parser-v3/src/test/resources/issue-2218/main.yaml b/modules/swagger-parser-v3/src/test/resources/issue-2218/main.yaml new file mode 100644 index 0000000000..35528fa09e --- /dev/null +++ b/modules/swagger-parser-v3/src/test/resources/issue-2218/main.yaml @@ -0,0 +1,16 @@ +openapi: 3.0.3 +info: + description: A service with remote models + version: 1.0.o + title: A service +paths: + /foo: + get: + description: Get Flag of flags + responses: + '200': + description: ok + content: + application/json: + schema: + $ref: './model.yaml#/components/schemas/FlagsOfFlags' \ No newline at end of file diff --git a/modules/swagger-parser-v3/src/test/resources/issue-2218/model.yaml b/modules/swagger-parser-v3/src/test/resources/issue-2218/model.yaml new file mode 100644 index 0000000000..102a5fa301 --- /dev/null +++ b/modules/swagger-parser-v3/src/test/resources/issue-2218/model.yaml @@ -0,0 +1,28 @@ +openapi: 3.0.3 +info: + description: Description + version: 1.0.0 + title: A title +paths: {} +components: + schemas: + Flag: + type: object + description: Active flag + properties: + isActive: + type: boolean + Flags: + type: object + description: Map of flags + additionalProperties: + type: array + items: + $ref: '#/components/schemas/Flag' + FlagsOfFlags: + type: object + description: Flag of flag configuration + additionalProperties: + type: array + items: + $ref: '#/components/schemas/Flags'