# standard-response-codes

Source: https://apigenie.pl/docs/linter/openapi/rules/standard-response-codes

A rule of the OpenAPI linter, which reads OpenAPI 3.0, 3.1 and 3.2 documents. 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**.

```yaml
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.

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