no-content-response-defined
This rule ensures that responses for HTTP status 204 do not define their response bodies.
Rule Details
The rationale behind this rule is to enforce the correct usage of HTTP status codes as per the HTTP specification. This helps in ensuring that the API behaves as expected and can interact correctly with clients.
The no-content-response-defined rule is designed to ensure that responses
for HTTP status 204 (No Content) do not define their response bodies. According
to the HTTP specification, a 204 response must not include a message body.
Configuration
None.
Examples
This rule should be used whenever an OpenAPI schema is being defined.
Good. The following schema does not define any response body, thus making it obvious.
paths:
/users/{id}:
delete:
responses:
"204":
description: User deleted successfully.
Bad. The following schema defines a non-empty response body, thus defying the purpose of the 204 status code.
paths:
/users/{id}:
delete:
responses:
"204":
description: User deleted successfully.
content:
application/json:
schema:
type: object
When Not to Use It
We recommend to always use this rule.
Automatic fixes
When invoked with --fix, this rule removes content from enabled 204
responses.
Compatibility
This rule is compatible with all OpenAPI 3.x version.