Skip to content

Schema with Additional properties was not solving remote refs #342 #423 #605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 21, 2017
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 @@ -15,6 +15,7 @@
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.parser.ResolverCache;
import io.swagger.v3.parser.models.RefFormat;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.LoggerFactory;

import java.net.URI;
Expand Down Expand Up @@ -97,21 +98,48 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
processRefProperty(prop.getValue(), file);
} else if (prop.getValue() instanceof ArraySchema) {
ArraySchema arrayProp = (ArraySchema) prop.getValue();
if (arrayProp.getItems().get$ref() != null) {
if (arrayProp.getItems() != null && arrayProp.getItems().get$ref() != null &&
StringUtils.isNotBlank(arrayProp.get$ref())) {
processRefProperty(arrayProp.getItems(), file);
}
} else if (prop.getValue().getAdditionalProperties() != null) {
Schema mapProp = prop.getValue();
if (mapProp.getAdditionalProperties().get$ref() != null) {
processRefProperty(mapProp.getAdditionalProperties(), file);
} else if (mapProp.getAdditionalProperties() instanceof ArraySchema &&
((ArraySchema) mapProp.getAdditionalProperties()).getItems().get$ref() != null) {
((ArraySchema) mapProp.getAdditionalProperties()).getItems()!= null &&
((ArraySchema) mapProp.getAdditionalProperties()).getItems().get$ref() != null
&& StringUtils.isNotBlank(((ArraySchema) mapProp.getAdditionalProperties()).getItems().get$ref())) {
processRefProperty(((ArraySchema) mapProp.getAdditionalProperties()).getItems(), file);
}
}
}
}
if (schema instanceof ArraySchema && ((ArraySchema) schema).getItems().get$ref() != null) {
if(schema.getAdditionalProperties() != null){
Schema additionalProperty = schema.getAdditionalProperties();
if (additionalProperty.get$ref() != null) {
processRefProperty(additionalProperty, file);
} else if (additionalProperty instanceof ArraySchema) {
ArraySchema arrayProp = (ArraySchema) additionalProperty;
if (arrayProp.getItems() != null && arrayProp.getItems().get$ref() != null &&
StringUtils.isNotBlank(arrayProp.get$ref())) {
processRefProperty(arrayProp.getItems(), file);
}
} else if (additionalProperty.getAdditionalProperties() != null) {
Schema mapProp = additionalProperty;
if (mapProp.getAdditionalProperties().get$ref() != null) {
processRefProperty(mapProp.getAdditionalProperties(), file);
} else if (mapProp.getAdditionalProperties() instanceof ArraySchema &&
((ArraySchema) mapProp.getAdditionalProperties()).getItems() != null &&
((ArraySchema) mapProp.getAdditionalProperties()).getItems().get$ref() != null
&& StringUtils.isNotBlank(((ArraySchema) mapProp.getAdditionalProperties()).getItems().get$ref())) {
processRefProperty(((ArraySchema) mapProp.getAdditionalProperties()).getItems(), file);
}
}

}
if (schema instanceof ArraySchema && ((ArraySchema) schema).getItems() != null && ((ArraySchema) schema).getItems().get$ref() != null
&& StringUtils.isNotBlank(((ArraySchema) schema).getItems().get$ref())) {
processRefProperty(((ArraySchema) schema).getItems(), file);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,17 @@ public void testInlineModelResolverByUrl(@Injectable final List<AuthorizationVal
assertNotNull(userAddress.getProperties().get("street"));
}

@Test
public void testRefAdditionalProperties() throws Exception {
OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/additionalProperties.yaml");

Assert.assertNotNull(openAPI);
Assert.assertTrue(openAPI.getComponents().getSchemas().size() == 3);
Assert.assertNotNull(openAPI.getComponents().getSchemas().get("link-object"));
Assert.assertNotNull(openAPI.getComponents().getSchemas().get("rel-data"));
Assert.assertNotNull(openAPI.getComponents().getSchemas().get("result"));
}


private static int getDynamicPort() {
return new Random().ints(10000, 20000).findFirst().getAsInt();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
openapi: 3.0.0
servers:
- url: http://swagger.io/show-bug
info:
title: Test API
version: 1.0.0
paths:
"/tests":
get:
operationId: listTests
responses:
'200':
description: Returns results.
content:
application/json:
schema:
"$ref": "./globals.yaml#/components/schemas/result"
22 changes: 22 additions & 0 deletions modules/swagger-parser-v3/src/test/resources/globals.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
components:
schemas:
link-object:
type: object
additionalProperties:
"$ref": "#/components/schemas/rel-data"
rel-data:
type: object
required:
- href
properties:
href:
type: string
note:
type: string
result:
type: object
properties:
name:
type: string
_links:
"$ref": "#/components/schemas/link-object"