standard-response-codes

Since 0.0.1 · In the rulesets: Recommended at error, Strict at error, All at error

This rule checks that every response is keyed by a three-digit HTTP status code from 100 to 599, by a range from 1XX to 5XX, or by default.

Rule details

HTTP defines the status codes as three digits whose first one is the class of the response, and OpenAPI spells a range of them with two capital X. A key outside that form, 2xx, 0200, 600, is not a status code any client will see: validators skip the response, generated clients have no branch for it, and a mock server never answers with it.

The rule reports Operation uses non-standard response code (...) on each such response. It does not check that a code is registered with IANA: 460 passes. The default response, which OpenAPI allows for every code the other entries do not list, passes too.

Examples

Good.

paths:
  /users:
    get:
      responses:
        "200":
          description: OK
        "4XX":
          description: The request is invalid.
        default:
          description: An unexpected error.

Bad. A range in lower case and a code of four digits.

paths:
  /users:
    get:
      responses:
        "2xx":
          description: OK
        "0404":
          description: Not Found

Turn it off or change its severity

In apigenie.yaml, off turns the rule off and warning or error sets its severity; a rule with options takes the severity and the options as a pair, [warning, options]. lint.rules has the details.

commands:
  lint:
    rules:
      standard-response-codes: off
Was this helpful?