Skip to content
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

Add nullable property to indicate a type can be null #1067

Closed
santialbo opened this issue Jan 21, 2021 · 3 comments
Closed

Add nullable property to indicate a type can be null #1067

santialbo opened this issue Jan 21, 2021 · 3 comments

Comments

@santialbo
Copy link

Current situation

Nullable types are very common in JSON world.
In order to make a type nullable either you have to add "null" to the types array or use oneOf

{ "type": ["string", "null"] }
{ "oneOf": [ { "type": "string" }, { "type": "null" } ] }

Rationale

I believe this approach of making a type nullable is not very intuitive 1.

At least one other specification (OpenAPI) supports an extension of the JSON schema spec that includes the nullable property2.

I suggest adding this nullable: boolean property to the JSON schema spec as a more intuitive and less verbose way of making types nullable.

1 https://stackoverflow.com/search?q=json+schema+nullable
2 https://swagger.io/specification/#fixed-fields-20

@santialbo
Copy link
Author

Ignore this, nullable has been removed from the upcoming Open API spec
OAI/OpenAPI-Specification#2246

@Relequestual
Copy link
Member

@santialbo It might be worth noting that OAS didn't just remove nullable, but they will be fully moving over to supporting JSON Schema draft 2020-12 rather than having a subset superset of a rather outdated version of JSON Schema.

We've been working closely with them for at least the past year (probably more) to make it happen.

I'm personally really proud of what our team has achieved! =]

@santialbo
Copy link
Author

Thanks for the heads up @Relequestual 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants