-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
Confusion around null values in spec and schema #297
Comments
Thanks for taking the time to open the issue. JSON Schema requires you to mention that a property can be nullified. For example, take this schema: {
"type": "object",
"properties": {
"test": {
"type": "string"
}
}
} A fairly simple one, of an object with one property {
"test": "hello"
} {
"test": null
} You'll see that the one with the |
+1 |
1 similar comment
+1 |
Tackling PR: #741 |
#894 added null support in 3.0. |
This confused the heck out of me. I found some hints on this issue list scattered across various issues but I still opted to ask a simple question at https://stackoverflow.com/q/45575493/131929. |
@marcelstoer Answered on Stackoverflow. @webron Unless I'm reading the JSON Schema spec wrong, it looks like that validator is invalid. null is always a valid string http://json-schema.org/latest/json-schema-validation.html#rfc.section.3.1 |
which validator? |
The one you referenced here #297 (comment) to justify why null is not valid. |
Okay, and just so we're on the same page - did you reference draft 06's validation where that was for OAS2 that used draft 04? |
Draft 04 said the same thing https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-3.1 |
This seems to come down to whether you consider the JSON concept of null as mapping to a string with the |
Are the I'll give you a hint why I think that wasn't the intent. Do you see the |
:-) LOL ok. That might be definitive then. I'll fix my answer on SO. |
See this topic for context: swagger-api/swagger-js#268
When I discovered those exceptions in swagger-js, I initially thought it was just an issue of error handling in the JS. During that discussion, I was informed that the Swagger spec and schema technically do not support null values for some fields (get, post, put, operations, for example).
I just wanted to provide a little feedback as a new user that this was both a bit surprising and confusing. I tried reading through both the spec and schema to determine whether my APIs behavior of serializing null values contradicted the Swagger spec or schema but couldn't find anything that indicated either way.
All that said, I'm hoping someone can explain the decision to explicitly disallow null values for these types of fields. Serializing null values from APIs seems like something that isn't uncommon and not supporting that was just a bit surprising.
Thanks!
Chris
The text was updated successfully, but these errors were encountered: