Ensures that every operation in your API document has at least one successful (200-299) HTTP response defined.
| OAS | Compatibility |
|---|---|
| 2.0 | ✅ |
| 3.0 | ✅ |
| 3.1 | ✅ |
| 3.2 | ✅ |
One of the main goals of your API description (and your API documentation) is to help consumers understand how your API behaves and what to expect when working with it.
When designing your APIs, every operation should have a successful HTTP response. If it doesn't, what is the purpose of the operation? Even if there is no response content (204), it can still return a successful response with no content. You can greatly improve the developer and user experience of your APIs by making it a standard to provide this information.
| Option | Type | Description |
|---|---|---|
| severity | string | Possible values: off, warn, error. Default: warn (in recommended configuration). |
| validateWebhooks | boolean | Determines if responses inside webhooks are validated. Default: false. |
| disallowDefault | boolean | Determines if a default response is disallowed from satisfying the rule. Default: false. |
An example configuration:
rules:
operation-2xx-response: errorThe following example enables validation of responses inside webhooks:
rules:
operation-2xx-response:
severity: error
validateWebhooks: trueBy default, a default response counts as a successful response. Set disallowDefault: true to require an explicit 2xx status code:
rules:
operation-2xx-response:
severity: error
disallowDefault: trueWith disallowDefault: true, the following operation is reported, because default describes the responses the operation does not list rather than what a successful call returns:
post:
responses:
default:
$ref: ../components/responses/Problem.yamlThis matters for code generation: a generator reads the 2xx response to produce the return type of the operation. A default-only operation gives it no success shape to model, so the generated client falls back to an untyped or empty result.
Given this configuration:
rules:
operation-2xx-response: errorExample of incorrect operation response:
post:
responses:
'400':
$ref: ../components/responses/Problem.yamlExample of correct operation response:
post:
responses:
'200':
$ref: ../components/responses/Success.yaml
'400':
$ref: ../components/responses/Problem.yaml