Description
PUT can create a resource or replace an existing one. Document the success response for each outcome your endpoint supports.
Potential impact
Clients may otherwise treat a newly created item as an update or try to read a missing result body.
Remediation
Use 201 for creation. For a successful replacement, document 200 when the server returns a result or 204 when it returns no body. Add a schema only for a body the server sends.
Examples
The example adds separate 201 and 204 entries alongside the existing default response.
Before
json
{
"openapi": "3.0.0",
"paths": {
"/item": {
"put": {
"operationId": "updateItem",
"summary": "Update item",
"responses": {
"default": {
"description": "Error"
}
}
}
}
}
}
After
json
{
"openapi": "3.0.0",
"paths": {
"/item": {
"put": {
"operationId": "updateItem",
"summary": "Update item",
"responses": {
"201": {
"description": "Item created successfully"
},
"204": {
"description": "Item updated successfully"
},
"default": {
"description": "Error"
}
}
}
}
}
}