Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Supporting null as valid values in validation #228

Closed
hhp21 opened this issue Jun 10, 2015 · 4 comments
Closed

Supporting null as valid values in validation #228

hhp21 opened this issue Jun 10, 2015 · 4 comments

Comments

@hhp21
Copy link

hhp21 commented Jun 10, 2015

As per OAI/OpenAPI-Specification#229, it seems like the current 2.0 spec doesn't have a way to let you specify whether you allow nulls as valid values. There are valid use cases either way but right now it seems that all null values will fail validation.

Any possibility to add support for this in swagger tools, with/without support from spec?

@whitlockjc
Copy link
Member

If the Swagger spec does not allow nulls, neither will swagger-tools as we use the JSON Schema from Swagger to do the first pass (structural) validation. As for making swagger-tools work with nulls, I don't see how without having a custom JSON Schema and I don't think that's a good idea. I also would rather be Swagger compliant if it were up to me.

Sorry about this but as soon as Swagger supports it, swagger-tools will.

@anthony-o
Copy link

Couldn't swagger-tools support a x-nullable property like other implementations did? (for OpenAPI 2 specification)

@leedm777
Copy link

OpenAPI 3.0 adds support for nullable, which seems relevant to this issue.

@anthony-o
Copy link

Yes, but sadly swagger-tools doesn't support this version of the specs (yet ?) :(
In this SO answer it is advised to put an array as the value of the type field (type: ['string','null']) but I don't think that it works with swagger-tools at is not in the 2.0 specs.
This SO answer advises to use the vendor extension x-nullable (but that is not supported by swagger-tools).
But this nullable feature is asked by many people on Stackoverflow & the internet...

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

No branches or pull requests

4 participants