Skip to main content

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.

PropertyValue
EnabledYes
Maximum SeverityError
MessageInvalid HTTP status code/range found.
CodeOPENAPI3SYNTAX_V060
TypeValidation
Rule SystemSyntax
Broad CategoryResponses
Products ImpactedAPI Transformer, Code Generation, Developer Experience Portal
Tagsopenapi3 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