-
Notifications
You must be signed in to change notification settings - Fork 378
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
Rule #123 Null values should have their fields removed – still valid? #498
Comments
Before we go into deeper discussions, can we agree on this?
|
Link to the rule in question: https://opensource.zalando.com/restful-api-guidelines/#123 |
Almost 😉 The only exception is the second use case: Optional field, which can be
Example 1 {
"optional_field": null
} Example 2 {} Both examples would be possible and are treated semantically the same on API backend side. The API consumer has no guarantee about whether the provided |
That's what my ✔️ was symbolizing. ✔️ satisfied schema |
This is exactly what rule 123 is enforcing. |
From my understanding it lacks the other part of even making |
Ok, to be totally precise: OpenAPI 3
RESTful API Guidelines
|
Thanks for clarifying. I think the second cross in first row of “RESTful API Guidelines” should be a checkmark, no? Apart from that I would say it’s clear to me now. We can close this issue, if you think it doesn’t serve any other purpose. |
I feel that we should be more precise in the rule and state that
|
Conclusion: We changed the wording of the rule to something along the lines of
It basically leaves engineers some freedom. They can choose to use |
Thanks, @whiskeysierra . You can close this issue then, I guess. |
Rephrased rule about null/absent properties
I had a discussion in my team whether to omit or not
null
valued fields. Pretty clear is that optional fields can always be dropped, as there is no guarantee about their existence. But let’s imagine we are talking about a mandatory field.In OpenAPI 2 there was no way to define
null
as a possible way, I learned. In OpenAPI 3, someone can definenullable: true
to expressnull
valued fields.Most statically typed languages probably will treat a missing field and a
null
valued field the same (e.g. Scala encodes both withNone
in the case of anOption
). For JavaScript someone would have to come up with a solution to check two things:undefined
)?null
or something else?By not dropping
null
valued, mandatory fields, the first check is unnecessary and the API spec can be treated as a real contract. Another option would be to make it explicit, thatnull
is not a valid value. In this scenario it is to a certain extend unclear for the API consumer what happens with the field:null
in the response of aGET
query for the same resource, as provided in thePOST
/PUT
request to create it initially?GET
query?At the end I argue, the API should respect the provided input (e.g.
null
), if it is valid according to the JSON spec (which is the case fornull
) and explicitly handle it in some way expressing the business rules a/o logic. The latter can be propagating and keeping it or dropping it and therefore not ensuring that it returns the valuenull
eventually.Omitting a field is “lack of information”, while having it set to
null
does convey information… imho. Even the description of the rule states, that there are use cases where “using null” is important, e.g. JSON Merge Patch.The text was updated successfully, but these errors were encountered: