mma5997
5 years agoOccasional Contributor
How to have a custom status code in response
responses:
'777':
description: My Custom
content:
application/json:
schema:
type: string
If I have "777" like fieldName for the status code in OAS3.0 spec YAML, then the editor.swagger.io throws an error as
"should only have three-digit status codes, `default`, and vendor extensions (`x-*`) as properties"
If I have the same status code in Swagger2.0 spec YAML, as below, then it doesn't throw an error.
responses:
'777':
description: custom
schema:
type: string
PS: I checked the indentation, it seems correct because if I change "777" in OAS3.0 spec YAML to standard status code like "400", "200" then it doesn't throw an error.
OpenAPI only supports the standard HTTP status codes from the 1xx-5xx range. You can provide custom codes and messages in the body of error responses, for example:
responses: '400': description: Bad request content: application/json: schema: type: object properties: code: type: integer example: 777 message: type: string example: Lorem ipsum