Skip to content

Commit

Permalink
Merge pull request #1541 from GabrielCastro/fix/schema-parsing-incons…
Browse files Browse the repository at this point in the history
…istencies

fix schemas parse inconsistencies
  • Loading branch information
gracekarina authored Apr 20, 2021
2 parents 403fd0c + f8ade46 commit cbb7b77
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ public Response response(ObjectNode node, String location, ParseResult result) {
result.invalidType(location, "$ref", "string", node);
}
} else {
output.responseSchema(Json.mapper().convertValue(schema, Model.class));
output.responseSchema(definition(schema, location + ".schema", result));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,39 @@ public void testIssuei432() {
assertEquals("attribute paths.'/tickets'(get).responses.200.title is unexpected",result.getMessages().get(0));
}

@Test
public void testIssue1541() {
SwaggerParser parser = new SwaggerParser();
final Swagger swagger = parser.read("src/test/resources/issue-1541/main.yaml");
assertNotNull(swagger);

Model inlineSchema = swagger.getPaths()
.get("/inline_response")
.getGet()
.getResponses()
.get("200")
.getResponseSchema();

assertNotNull(inlineSchema);
assertNotNull(inlineSchema.getProperties());
assertNotNull(inlineSchema.getProperties().get("a"));
assertEquals("number", inlineSchema.getProperties().get("a").getType());

Model responseRef = swagger.getPaths()
.get("/ref_response")
.getGet()
.getResponses()
.get("200")
.getResponseSchema();

assertEquals("#/definitions/ref_response_object", responseRef.getReference());

Model refSchema = swagger.getDefinitions()
.get("ref_response_object");

assertEquals("number", refSchema.getProperties().get("a").getType());
}

@Test
public void testRequiredItemsInComposedModel() {
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("src/test/resources/allOf-example/allOf.yaml", null, true);
Expand Down
38 changes: 38 additions & 0 deletions modules/swagger-parser/src/test/resources/issue-1541/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
swagger: '2.0'
info:
title: 'Issue 1541'
version: '1.0'
consumes:
- application/json
paths:
/inline_response:
get:
responses:
'200':
description: ok
schema:
type: object
additionalProperties: false
properties:
a:
type: number
/ref_response:
get:
responses:
'200':
description: ok
schema:
$ref: '#/definitions/ref_response_object'
definitions:
ref_response_object:
type: object
additionalProperties: false
properties:
a:
type: number
b:
type: object
additionalProperties: false
properties:
c: { type: number }
d: { type: string }

0 comments on commit cbb7b77

Please sign in to comment.