Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<AuthorizationValue> authorizationValues = null;

ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation(inputSpec, authorizationValues, options);

OpenAPI openAPI = result.getOpenAPI();

Map<String, Schema> 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");
}

}
16 changes: 16 additions & 0 deletions modules/swagger-parser-v3/src/test/resources/issue-2218/main.yaml
Original file line number Diff line number Diff line change
@@ -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'
28 changes: 28 additions & 0 deletions modules/swagger-parser-v3/src/test/resources/issue-2218/model.yaml
Original file line number Diff line number Diff line change
@@ -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'
Loading