How to specify a property as null or a reference? discusses how to specify a property as null or a reference using jsonschema.
I\'m looking to do the same thing with
Not easy to do that. Even almost impossible. Your options :
There is a very long discussion about this point, maybe one day it will be done...
You can use vendors extensions like x-oneOf and x-anyOf. I have already taken this hard way: You must to upgrade all used 'swagger tools' to take into account these vendors extensions.
In my case, we needed 'only' to :
It was a year ago, maybe now ...
Many projects don't need anyOf and oneOf, why not us ?
In OpenAPI 3.0, you can use:
"foo": {
"nullable": true,
"allOf": [
{
"$ref": "#/definitions/Foo"
}
]
}
YAML version:
foo:
nullable: true
allOf:
- $ref: '#/definitions/Foo'
Wrapping $ref
into allOf
is needed to combine the $ref
with other keywords - because $ref
overwrites any sibling keywords. This is further discussed in the OpenAPI Specification repository: Reference objects don't combine well with “nullable”