valid-response-status-code-or-range
Overview
This rule belongs to the openapi-v3-syntax-validation
ruleset and states that:
The Responses Object key must be a valid HTTP status code/range or set to default
. The key must be enclosed in quotation marks for compatibility between JSON and YAML. If the key is an explicit HTTP status code, then it must be valid according to RFC7231 and possibly listed in the registered status codes in the IANA Status Code Registry. if the key represents a range of status codes it must contain the uppercase wildcard character X
e.g. 2XX represents all response codes between [200-299]. Only the following range definitions are allowed: 1XX, 2XX, 3XX, 4XX, and 5XX. To represent undeclared responses, the key default
can be used.
Property | Value |
---|---|
Enabled | Yes |
Maximum Severity | Error |
Message | Invalid HTTP status code/range found. |
Code | OPENAPI3SYNTAX_V060 |
Type | Validation |
Rule System | Syntax |
Broad Category | Responses |
Products Impacted | API Transformer, Code Generation, Developer Experience Portal |
Tags | openapi3 openapi syntax validation http status status code status range range code http status responses response |
Suggested Fixes
- Make sure that the value of the HTTP status code is enclosed in single or double quotation marks.
- Ensure that the HTTP status code is valid and falls in the range 1XX - 5XX.
- When using ranges, only valid HTTP status code ranges are 1XX, 2XX, 3XX, 4XX, and 5XX. Ranges like 50X or 2X0 etc. are not allowed.
- Use only uppercase wildcard character X for HTTP response status ranges.
- Use key
default
to represent responses whose status codes are unknown/undeclared.
For More Information
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#patterned-fields-1
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#responses-object
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#http-status-codes
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#patterned-fields-1
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#responses-object
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#http-status-codes
- https://datatracker.ietf.org/doc/html/rfc7231#section-6
- https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#openapi-specification
- https://docs.apimatic.io/rulesets/overview/