Skip to content
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

fixing bug resolving additionalProperties #342 #602

Merged
merged 2 commits into from
Dec 20, 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 @@ -116,6 +116,29 @@ public String processRefToExternalDefinition(String $ref, RefFormat refFormat) {
}
}
}
if (model instanceof ModelImpl) {
ModelImpl modelImpl = (ModelImpl) model;
Property additionalProperties = modelImpl.getAdditionalProperties();
if (additionalProperties != null) {
if (additionalProperties instanceof RefProperty) {
processRefProperty(((RefProperty) additionalProperties), file);
} else if (additionalProperties instanceof ArrayProperty) {
ArrayProperty arrayProp = (ArrayProperty) additionalProperties;
if (arrayProp.getItems() instanceof RefProperty) {
processRefProperty((RefProperty) arrayProp.getItems(), file);
}
} else if (additionalProperties instanceof MapProperty) {
MapProperty mapProp = (MapProperty) additionalProperties;
if (mapProp.getAdditionalProperties() instanceof RefProperty) {
processRefProperty((RefProperty) mapProp.getAdditionalProperties(), file);
} else if (mapProp.getAdditionalProperties() instanceof ArrayProperty &&
((ArrayProperty) mapProp.getAdditionalProperties()).getItems() instanceof RefProperty) {
processRefProperty((RefProperty) ((ArrayProperty) mapProp.getAdditionalProperties()).getItems(), file);
}
}

}
}
if (model instanceof ArrayModel && ((ArrayModel) model).getItems() instanceof RefProperty) {
processRefProperty((RefProperty) ((ArrayModel) model).getItems(), file);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import static org.testng.Assert.fail;

public class SwaggerParserTest {

@Test
public void testModelParameters() throws Exception {
String yaml = "swagger: '2.0'\n" +
Expand Down Expand Up @@ -1026,4 +1027,20 @@ public void testRefNameConflicts() throws Exception {
assertEquals("local", swagger.getDefinitions().get("PersonObj").getProperties().get("location").getExample());
assertEquals("referred", swagger.getDefinitions().get("PersonObj_2").getProperties().get("location").getExample());
}

@Test
public void testRefAdditionalProperties() throws Exception {
Swagger swagger = new SwaggerParser().read("src/test/resources/additionalProperties.yaml");

Assert.assertNotNull(swagger);

Assert.assertTrue(swagger.getDefinitions().size() == 3);

Assert.assertNotNull(swagger.getDefinitions().get("link-object"));
Assert.assertNotNull(swagger.getDefinitions().get("rel-data"));
Assert.assertNotNull(swagger.getDefinitions().get("result"));
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
swagger: "2.0"
info:
title: Test API
version: 1.0.0
host: swagger.io
basePath: /show-bug
schemes:
- http
produces:
- application/json
consumes:
- application/json

paths:
/tests:
get:
operationId: listTests
responses:
200:
description: Returns results.
schema:
$ref: "./globals.yaml#/definitions/result"
23 changes: 23 additions & 0 deletions modules/swagger-parser/src/test/resources/globals.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
definitions:
link-object:
type: object
additionalProperties:
$ref: '#/definitions/rel-data'

rel-data:
type: object
required:
- href
properties:
href:
type: string
note:
type: string

result:
type: object
properties:
name:
type: string
_links:
$ref: "#/definitions/link-object"