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.
|
property = Json.mapper().readValue(Json.pretty(property), Schema.class); |
|
} 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.
As indicated by the OpenAPI documentation, the
typekeyword can be excluded to match any data type.However, from what I can tell, there isn't a way to actually achieve this in Swagger Core. Even if a
Schemais manually created with a nulltype(e.g. using a customModelConverter), Swagger Core will automagically use typeobjectfor it. This is decidedly not equivalent to the arbitrary type, as it will not matchstring,number,integer,boolean, orarraytypes.Tracing through the code, this appears to be due to
ModelResolverusing Jackson to clone theSchema, which due to the implementation inModelDeserializer, turns the null type back into theobjecttype.swagger-core/modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.java
Line 907 in 56d233b
swagger-core/modules/swagger-core/src/main/java/io/swagger/v3/core/util/ModelDeserializer.java
Lines 78 to 80 in 438230d
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.
Related to this issue is #3834, which could not be implemented without having a way of supporting the arbitrary type.