question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Must HTTP Status Codes be strings?

See original GitHub issue

The 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:closed
  • Created 5 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
lafrechcommented, Nov 17, 2018

Hmmm, OK. I think I see. It’s more a language / format / representation issue than a spec issue.

0reactions
MikeRalphsoncommented, Feb 19, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Status codes in HTTP - W3C
These codes indicate success. The body section if present is the object returned by the request. It is a MIME format object. It...
Read more >
A Complete Guide and List of HTTP Status Codes
A complete list of HTTP status codes with explaination of what they are, why they occur and what you can do to fix...
Read more >
List of HTTP status codes - Wikipedia
All HTTP response status codes are separated into five classes or categories. The first digit of the status code defines the class of...
Read more >
Should error codes in JSON be integers or strings?
Or, you could also add the http response code inside the object, but that's redundant with the response itself, but might be useful...
Read more >
Treat HTTP status codes as strings - Ivan Sagalaev
Treat HTTP status codes as strings · 1xx: server programmer is too smart · 2xx: success · 3xx: your client HTTP library is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found