-
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
Do not force "" for http status code #2171
Comments
I think this would not be an improvement to OpenAPI. in terms of general principles, OpenAPI exists to aid interoperability. changes that add ambiguity to how an API can be represented in OpenAPI are counter to that. every tool would now have to look for numeric keys in addition to string keys. it opens up the possibility for collisions if both integer 200 and string "200" are present. it brings in issues of comparing numbers (is having a single, consistent way to represent an http status obviates all these problems. I appreciate that the aesthetics of having to quote these, when you don't normally have to quote object keys in YAML, is suboptimal. but it is best for keys to remain as strings. it's unfortunate that the swagger editor uses integer keys. they shouldn't. it looks like these are implicitly converted to strings by their YAML parser (which is not usual and seems plainly incorrect according to the YAML spec - but that's far afield). I will open an issue to correct their examples (unless, of course, the consensus on this issue goes the other way). |
In the HTTP/1.1 standard (RFC 7231: https://tools.ietf.org/html/rfc7231#page-47) response status code is described as:
In all of the languages and libraries I know, it is implemented as an integer. Forcing in OpenAPI spec to represent response status code as a string is misleading, against HTTP standard and all of the software implementations. What's worse is that it's done only to cover the limitations of the JSON format not being able to handle numeric kets or to avoid double keys in YAML. I believe such things should be covered by the linting tools, instead OpenAPI spec introducing misleading requirements. |
The |
I've worked with a lot of http libraries, the string/integer decision seems like a coin toss sometimes. arguably an integer is more appropriate, but it doesn't really matter. OpenAPI documents are JSON (even when they are YAML), and in JSON, object keys are strings, not integers. |
I am keen to see the library which exposes response status code as string :) The internals of OpenAPI spec does not matter so much. If the format (like YAML) offering easy transformation to what OpenAPI uses under the hood, this should not force on the format to use something not natural. YAML keys wrapped into I believe OpenAPI spec should focus on the value it offers (and it's undoubtedly great!) instead of specifying format details. |
@MikeRalphson |
@pkuczynski your proposal would allow situations like this responses:
200:
...
"200":
... which would need additional wording in the Spec to ensure the uniqueness of map keys and, as a result, require additional work from tooling vendors. Using a single data type (string in this case) helps keep things simple. |
@hkosova this is a very unlikely situation, and I think very easy to spot when reviewing the spec (source or rendered to a nice doc) - duplicated keys would really stand out. And still, if one would miss it, he could use one of the many linting tools to ensure the syntax of the spec is correct. I believe that it would be better to say that response code need to be unique, instead of forcing |
@pkuczynski unlikely based on what? Two people merge a change to an OpenAPI document, both adding 404, one uses string the other doesn't. Now you have a |
This should be picked up by git as a merge conflict, so the second-person would see it and resolve it. In a rare case of mistake, validation should report it... |
That's not actually how git works. 😅 |
I know how git works, trust me :) |
I'm sure. Anyway, due to the need to support 4XX and the default value, this does need to be a string. Thanks for the interesting discussions. |
This entire ticket, and #2147 before it, doesn't make sense. In JSON the only valid format for an object key is a string, so any yaml-to-json translator will turn a numeric key into a stringy key. For example:
(where yaml2json is a bash function, and I can guarantee that these YAML and JSON backends work properly (the YAML one having been written by the inventor of YAML):
|
@karenetheridge I agree with you. That's why I believe spec should not mention that keys need to be strings, as it is obvious for json and does enforce people to write ugly yaml:
instead of totally fine and more yaml-natural way:
That was the whole point if this issue: don't mention the string format for status code and leave that up to the file format. Do you know what I mean @karenetheridge? |
I am referring to this sentence from https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md |
@pkuczynski I see what you mean. I agree, I think, but I will sit this one out as I am 1. not heavily involved in OpenAPI, and 2. work in a language that only has stringy keys so the YAML loading would work fine for me in any case (I apologize for my privilege blinding me to the oppression that others are dealing with) 😁 |
At least one person understands what I am talking, thank you @karenetheridge :) |
@pkuczynski @karenetheridge what @philsturgeon is this:
Given a long list of errors, where there's already a
Saving two keystrokes to quote your keys is not worth this headache. |
I know what @philsturgeon is trying to say, buts I simply don't think OpenAPI should be worried about details of formatting. It should be left alone to the specific format itself. It.would be enough to say, that error codes should be unique and the linting tool should be the one holding the guard. Currently, some yaml linters happily accept duplicated keys no matter if they in or without quotes. I used following example: ---
responses:
404: abc
404: cde
"404": abcd And following lint parsers considered this code totally valid (despite using quotes):
They clearly don't follow the spec https://yaml.org/spec/1.2/spec.html#id2759572, but it would only mean that your enforcement of putting things into quotes does not serve the purpose. It should rather formulate that keys should be uniq. Thats also what YAML 1.2 spec says, but not JSON spec (JSON's RFC4627 requires that mappings keys merely “SHOULD” be unique) Following some other YAML parsers online, implementing YAML 1.2 spec you will notice that they would report duplicated keys in this example: ---
responses:
404: abc
"404": cde So if python yaml parser does not do that, you should report an error there, instead of forcing people to write in yaml response statuses wrapped in quotes |
I appreciate the mentions but I have to keep coming back here to unsubscribe. |
@pkuczynski Pointing out the wobbly inconsistency of YAML tooling is really not making your case any stronger. I think I'll unsubscribe from this, too, as I find the whole complaint utterly baffling. I'm of the "there should be one way to do things" mentality when it comes to specs like this, and there's clearly only one option that works for every format and every use of that field (which is not limited to numbers). Everything else is needlessly complicated. |
In JSON the key which is a number must be wrapped into
""
. This is not the case of yaml format. Different formats, different requirements. It does not make sense to force json requirements into yaml and this makes it really annoying to have to use"400": ...
in YAMLPlease also note that https://editor.swagger.io does not wrap status codes into "", which is correct, but contradictory to this spec:
I propose to remove the requirement of providing status codes as strings in YAML and only keep it for JSON, leaving the alignment for the transformation tool between two formats.
I already created #2147, which got rejected, so now I am opening this issue as the proposal for the next version of the spec.
The text was updated successfully, but these errors were encountered: