Reviewer · API
Document full-replace semantics
When a PUT or PATCH endpoint performs a full replacement rather than merging or partially updating the existing resource, this must be stated explicitly in both the schema description and the request/response examples. Consumers naturally assume update endpoints merge new fields with existing ones, so silent full-replace behavior (where omitted fields are...
When a PUT or PATCH endpoint performs a full replacement rather than merging or partially updating the existing resource, this must be stated explicitly in both the schema description and the request/response examples. Consumers naturally assume update endpoints merge new fields with existing ones, so silent full-replace behavior (where omitted fields are reset to defaults, or array/object fields are entirely overwritten) is a common source of data-loss bugs and confusion.
For every endpoint that replaces rather than merges:
- State plainly in the operation/field description that there is no partial update, e.g. “A PATCH request replaces the whole array; it does not merge entries by key” or “Sending the same request twice leaves the resource unchanged, but omitting a field resets it to its default.”
- Provide at least one example that demonstrates the consequence of this behavior, such as sending only the fields being changed and showing that other settings are lost, alongside an example showing how to preserve existing settings by re-sending them.
- When describing a request example that updates one part of a resource, be explicit about what else is affected, e.g. “Adds a custom type with a value pattern… This request replaces the existing custom types and settings, so include any you want to keep” rather than only describing the intended change.
This ensures API consumers can predict the effect of a request without needing to read the implementation.