-
Notifications
You must be signed in to change notification settings - Fork 537
Description
It appears that, as of version 1.0.32, the Java Swagger parser suffers from the same issue referenced in swagger-api/swagger-ui#1747 and swagger-api/swagger-js#681.
Relevant code:
SwaggerParser parser = new SwaggerParser();
Swagger swagger = parser.read(input.getPath());
Yaml.pretty().writeValue(output, swagger);
where input and output are both of type File
Specifically, given the file ref.yaml containing
definitions:
ReferencedObject1:
type: object
title: ReferencedObject1
properties:
name:
type: string
description: My name
number:
type: string
description: My number
required:
- name
- number
ReferencedObject2:
type: object
title: ReferencedObject2
properties:
address:
type: string
description: My address
and an input file bug.in.yaml containing
swagger: '2.0'
info:
title: ParserBug
version: '1.0'
description: Demonstrates a parser bug
basePath: /parser
paths:
'/':
get:
operationId: getItem
responses:
'200':
description: successful response
schema:
allOf:
- $ref: './ref.yaml#/definitions/ReferencedObject1'
- $ref: './ref.yaml#/definitions/ReferencedObject2'
parser.read will generate
16:17:42.625 [main] WARN io.swagger.util.PropertyDeserializer - no property from null, null, {ENUM=null, TITLE=null, DESCRIPTION=null, DEFAULT=null, PATTERN=null, DESCRIMINATOR=null, MIN_ITEMS=null, MAX_ITEMS=null, MIN_PROPERTIES=null, MAX_PROPERTIES=null, MIN_LENGTH=null, MAX_LENGTH=null, MINIMUM=null, MAXIMUM=null, EXCLUSIVE_MINIMUM=null, EXCLUSIVE_MAXIMUM=null, UNIQUE_ITEMS=null, EXAMPLE=null, TYPE=null, FORMAT=null, READ_ONLY=null, VENDOR_EXTENSIONS={}, MULTIPLE_OF=null}
when it encounters the allOf definition, and will produce an output Swagger object that deserializes to:
---
swagger: "2.0"
info:
description: "Demonstrates a parser bug"
version: "1.0"
title: "ParserBug"
basePath: "/parser"
paths:
/:
get:
operationId: "getItem"
parameters: []
responses:
200:
description: "successful response"
(Note that the schema is missing from the output). The expected behavior was that an object with all of the members of the referenced items would have been produced as the schema.
If, however, the allOf is moved down to an explicit definition and referenced by the schema, like so:
swagger: '2.0'
info:
title: ParserBug
version: '1.0'
description: Demonstrates a workaround to the parser bug
basePath: /parser
paths:
'/':
get:
operationId: getItem
responses:
'200':
description: successful response
schema:
$ref: '#/definitions/OutputObject'
definitions:
OutputObject:
allOf:
- $ref: './ref.yaml#/definitions/ReferencedObject1'
- $ref: './ref.yaml#/definitions/ReferencedObject2'
Then no warning is generated, and the Swagger object contains:
---
swagger: "2.0"
info:
description: "Demonstrates a workaround to the parser bug"
version: "1.0"
title: "ParserBug"
basePath: "/parser"
paths:
/:
get:
operationId: "getItem"
parameters: []
responses:
200:
description: "successful response"
schema:
$ref: "#/definitions/OutputObject"
definitions:
OutputObject:
allOf:
- $ref: "#/definitions/ReferencedObject1"
- $ref: "#/definitions/ReferencedObject2"
ReferencedObject1:
type: "object"
required:
- "name"
- "number"
properties:
name:
type: "string"
description: "My name"
number:
type: "string"
description: "My number"
title: "ReferencedObject1"
ReferencedObject2:
type: "object"
properties:
address:
type: "string"
description: "My address"
title: "ReferencedObject2"
Thus, the allOf is respected in an explicit object definition, but not in the implicit definition under schema.
Above files are attached
bug.zip