Must HTTP Status Codes be strings?
See original GitHub issueThe Responses
object contains a {HTTP Status Code: Response
} mapping.
In all the examples I found, the status code is provided as a string:
{"200": {"description": "a pet to be returned"}}
I couldn’t find any requirement for it to be a string and integers are accepted by the validators I tried.
All I found was a PR changing from integer to string in all YAML examples.
Should I only use strings?
In JSON, only strings are valid keys. So the question could be rephrased as “which of the following two assumptions is correct”?
-
OpenAPI doesn’t specify that HTTP Status Codes should be strings because that’s implicit (JSON format). However, validation and display tools are being loose about that requirement.
-
OpenAPI uses some kind of “JSON superset” in which integer keys are considered valid.
I’m sorry if this is a silly question. I asked on SO and got no answer.
I’m pretty sure I’d be on the safe using using only strings, but I’d like to understand, and I’m surprised I didn’t find any explicit requirement.
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (5 by maintainers)
Top GitHub Comments
Hmmm, OK. I think I see. It’s more a language / format / representation issue than a spec issue.
One-off generation of JSON examples from the YAML is not “autogeneration” as I meant it. If we went down this route it would be an automated process to keep the two in step.