-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Clarification on nullable properties, OpenAPI 3.1 #3148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm aware this might be an issue with jsonschema itself too. If it makes sense for me to do so, I could close this issue and report a new one against jsonschema. |
Hmm, I actually think JSONSchema allows for option A. From the spec:
Assuming I've understood this correctly, both are valid options and it's a case of determining whether clarity trumps succinctness or not. I, for one, would love to see this detailed in the spec itself so I'll leave this open as a kind of docs RFE. |
Both options are valid. Sometimes there are multiple ways to define the same thing with JSON Schema.
Type-specific keywords (such as string-specific |
@hkosova is correct. Perhaps an example using We do not want to get into things like keyword applicability to types as that is a JSON Schema concern and OAS should not duplicate JSON Schema stuff. |
It's been nearly a year since multiple folks answered with "both are valid" and no further questions, so I'm closing this as resolved. |
According to the spec, neither are valid. |
@XedinUnknown that doc is about OpenAPI 3.0, whereas this discussion is about 3.1. |
https://spec.openapis.org/oas/latest.html#data-types @hkosova even for OpenAPI 3.1 spec doesn't mention that data types should support null. may i know how the nullable field is supported now actually? |
Need to know this information as well to make structs into pointer types when generating off openapi 3.1.0 yaml files |
The answer is the same as it always has been: That both of the options written out by the OP are supported in OAS 3.1. For information about which form your tool prefers, please contact your tooling vendor. |
OpenAPI 3.1 introduces support for jsonschema's
'null'
type, however, the OpenAPI 3.1 spec makes no mention of this leading to confusion on how to specify null objects. I've seen two common ways to represent nullable properties in the wild.Option A
Option B
Option A is more succinct but arguably incorrect, since
format
andmaxLength
are not applicable for thenull
type. It is rather common though. For example, GitHub's OpenAPI 3.1 specs does this:Option B is longer but appears (to me) to be technically correct.
Could we clarify which of these is correct? I assume we'd need a future MINOR or PATCH version if we wanted to (correctly?) forbid option A?
The text was updated successfully, but these errors were encountered: