How to specify a property as null or as a reference? discusses how to specify a property as null or as a reference using jsonschema.
I am going to do the same with swagger.
To repeat the answer to the above, using jsonschema you can do the following:
{ "definitions": { "Foo": { # some complex object } }, "type": "object", "properties": { "foo": { "oneOf": [ {"$ref": "#/definitions/Foo"}, {"type": "null"} ] } } }
The key point in the answer was the use of oneOf .
Key points of my question:
I have a complex object that I want to keep DRY, so I put it in the definition section for reuse in my specification: the values ββof other properties; response objects, etc.
In different places in my specification, a property can be a reference to such an object OR be null.
How do I specify this with Swagger that does not support oneOf or anyOf ?
Note: some swagger implementations use x-nullable (or something like that) to indicate the value of the property, which may be null, however, $ref replaces the object with what it refers to, so any use of x-nullable may seem x-nullable ignored.
source share