Invalid HTTP response status code

Check OpenAPI response-key syntax and the forms allowed by each version. Informational 1xx responses are valid.

Description

responses accepts individual HTTP status codes, including informational 1xx codes. default covers codes without a more specific entry. OpenAPI 3.0 also accepts the uppercase ranges 1XX through 5XX. OpenAPI 2.0 has no range syntax.

Potential impact

Tools may reject malformed keys. A valid code with the wrong meaning can also lead clients to mishandle a redirect or an error.

Remediation

List the codes your server returns. Check their meanings in the IANA registry, then validate the full document against its OpenAPI version.

Response-key examples

These OpenAPI 3.0 excerpts omit info.

Invalid response keys

json
{
  "openapi": "3.0.0",
  "paths": {
    "/": {
      "get": {
        "responses": {
          "50": {
            "description": "Invalid status"
          },
          "6xx": {
            "description": "Invalid range"
          }
        }
      }
    }
  }
}

Status codes whose meaning needs review

json
{
  "openapi": "3.0.0",
  "paths": {
    "/": {
      "get": {
        "responses": {
          "200": {
            "description": "OK"
          },
          "310": {
            "description": "Redirect"
          }
        }
      }
    }
  }
}

50 is too short and 6xx is outside the allowed ranges. 200 means success. 310 has no registered meaning. For a redirect, use the code the server sends, such as 301 or 302.

References