-
Notifications
You must be signed in to change notification settings - Fork 13
Description
Support Ticket 137 describes some known limitations of the swagger-models
library that defines the data structures for representing a Swagger spec in Java. swagger-models
holds the in-memory object graph produced by the swagger parser.
This can cause significant problems downstream, because swagger-models
is used by most of the Swagger-OpenAPI tools, including the Swagger-UI and code generators, as well as our own swagger-normalizer
, live views, Xtend code gen framework, etc.
We hope there will be a fix for these problems. In the meantime, the validator should warn in cases where a schema construct, though allowed by the Swagger specification, is not handled properly by swagger-models.
Borrowing from @andylowry explanations:
allOf Schema with top-level properties
Here's an example:
definitions:
person:
type: object
properties:
firstname:
type: string
lastname:
type: string
employee:
allOf:
- $ref: "#/definitions/person"
properties:
employeeID:
type: string
hireDate:
type: string
The problem is that, in that representation, the structure used for representing an allOf schema has no provision for direct properties of the allOf schema. So, contrary to the Swagger specification, the Swagger Parser is incapable of handling a schema with both allOf
and properties
.
Suggested warning text:
A schema with an 'allOf' constraint and a top-level properties list may not be handled correctly. Code generators and UI presentations may recognize properties inherited from schemas in the 'allOf' list, but ignore those in the top-level 'properties' list. Recommended workaround: add an inline object schema to the
allOf
list, and move the top-level properties into this schema.
allOf not recognized in certain contexts
Example:
person:
type: object
properties:
firstname:
type: string
lastname:
type: string
employeeList:
type: array
items:
type: object
allOf:
- $ref: "#/definitions/person"
- type: object
properties:
employeeID:
type: string
hireDate:
type: string
There is another Swagger parser bug, also related to the "swagger-models" representation of swagger specs. The problem is that there are a number of contexts where Swagger allows a schema, but where internally, a restricted form of schema representation is used. These include:
- Responses (but not body parameters)
- Array item types
- Property types in object schemas
The restricted representation has no support at all for allOf, and any allOf specifications in your schemas that appear in these contexts are simply dropped silently by the parser.
This means, for example, that the employeeList
schema is treated as an array of objects that have no defined properties. It's as if the definition of employeeList
looked like this (because the allOf
portion is simply ignored by the parser):
employeeList:
type: array
items:
type: object
Suggested warning text:
A schema in this context may not support the 'allOf' constraint. Code generators and UI presentations may omit properties and constraints defined in 'allOf' component schemas. Recommended workaround: define schema in the top-level 'definitions' object with the 'allOf' constraint, and reference that schema here.
additionalProperties not recognized
@andylowry , is there also a problem with recognition of additionalProperties in some cases? Or the combination of additionalProperties and statically defined properties?