-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
As indicated by the OpenAPI documentation, the type
keyword can be excluded to match any data type.
A schema without a type matches any data type – numbers, strings, objects, and so on.
However, from what I can tell, there isn't a way to actually achieve this in Swagger Core. Even if a Schema
is manually created with a null type
(e.g. using a custom ModelConverter
), Swagger Core will automagically use type object
for it. This is decidedly not equivalent to the arbitrary type, as it will not match string
, number
, integer
, boolean
, or array
types.
Tracing through the code, this appears to be due to ModelResolver
using Jackson to clone the Schema
, which due to the implementation in ModelDeserializer
, turns the null type back into the object
type.
swagger-core/modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.java
Line 907 in 56d233b
property = Json.mapper().readValue(Json.pretty(property), Schema.class); |
swagger-core/modules/swagger-core/src/main/java/io/swagger/v3/core/util/ModelDeserializer.java
Lines 78 to 80 in 438230d
} else { // assume object | |
schema = deserializeObjectSchema(node); | |
} |
Note that the equivalent type used in the documentation cannot be used either, because the arbitrary type is recursive — it is also the type of the items in the array. That is to say the arbitrary type could be an array containing arbitrary type items, which could also be arrays containing arbitrary type items, and so on.
components:
schemas:
AnyValue:
anyOf:
- type: string
- type: number
- type: integer
- type: boolean
- type: array
items: {}
- type: object
Related to this issue is #3834, which could not be implemented without having a way of supporting the arbitrary type.