Description
Perhaps more of a question than an issue report, but I am not sure how to combine “nullable” with a reference object; I have the impression they don't combine well?
In Swagger-UI issue 3325 I posted an example with the following schema. The intent is to express that both “dataFork” and “resourceFork” contain a Fork, except that “resourceFork” can also be null
, but “dataFork” cannot be null
. As was pointed out though, the schema is not in accordance with the OpenAPI v3.0.0 specification, due to the use of JSON Schema's {"type":"null"}
which has not been adopted in OpenAPI.
...
"File": {
"type": "object",
"properties": {
"name": { "type": "string" },
"dataFork": { "$ref": "#/components/schemas/Fork" },
"resourceFork": {
"anyOf": [
{ "type": "null" },
{"$ref": "#/components/schemas/Fork" } ] },
...
I considered I can instead express the example as follows, which as far as I can tell is at least in accordance with the OpenAPI specification? But the use of “anyOf” with only one schema inside seems clumsy, is there a better way to handle this? Essentially, a better way to combine “nullable” with the reference object?
...
"File": {
"type": "object",
"properties": {
"name": { "type": "string" },
"dataFork": { "$ref": "#/components/schemas/Fork" },
"resourceFork": {
"nullable": true,
"anyOf": [
{ "$ref": "#/components/schemas/Fork" } ] },
...