You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Open API 3.0 supports nullable types by setting the nullable: true field on schemas that contain a type.
Open API 3.1 drops support for the nullable field, instead going all in on adding type: "null" from the Json Schema spec.
The majority of the time when we want to emit type: "null" it is because a model property is nullable - it can be set to some type or null. It is relatively rarer that a model property would be only settable to null.
Since in Open API 3.1 type can also be an array now, support for nullable types can be done in 2 ways:
by adding a { type: "null" } sub-schema as part of an anyOf.
Adding "null" to the schema's type array.
There are subtle differences between these 2 options due to how Json Schema validation works. One example is with enums. To support nullable enums, either of these would be valid:
Open API 3.0 supports nullable types by setting the
nullable: true
field on schemas that contain atype
.Open API 3.1 drops support for the
nullable
field, instead going all in on addingtype: "null"
from the Json Schema spec.The majority of the time when we want to emit
type: "null"
it is because a model property is nullable - it can be set to some type or null. It is relatively rarer that a model property would be only settable tonull
.Since in Open API 3.1
type
can also be an array now, support for nullable types can be done in 2 ways:{ type: "null" }
sub-schema as part of ananyOf
."null"
to the schema'stype
array.There are subtle differences between these 2 options due to how Json Schema validation works. One example is with enums. To support nullable enums, either of these would be valid:
Note that in Option 2,
null
needs to be part of theenum
list.Currently our JSON Schema emitter emits option 1.
The text was updated successfully, but these errors were encountered: