“Any or all of a resource’s attributes MAY be included in the resource object included in a PATCH request.”
Is it allowed to require certain attributes to be always present in a PATCH call (at a certain endpoint)? In the extreme, this could be used to model a replace-update, when all attributes are required. Other use cases might have dependencies between attributes such as “if a is provided with a certain value, b must be present too”.
Requiring an attribute to be present in a resource object used used in a patch operation violates the specification:
If a request does not include all of the attributes for a resource, the server MUST interpret the missing attributes as if they were included with their current values.
However validating that an attribute would be present in a resource after applying the changes is okay.
What is your use case? What are you trying to achieve by enforcing replacement of some (or all) attributes? In general JSON:API specification is more focused on the result of an update rather than the applied change itself.
So the spec clearly says a server MUST not expect any attribute to be present. This paragraph of the spec somehow didn’t make it to my attention.
I know of two types of use cases:
a) Sometimes implementations can do replace updates directly, while partial updates require to fetch data from a database or upstream service. So to forbid partial updates can help performance.
b) Sometimes a set of attributes have dependencies on each other. E.g., one attribute’s value defines which other values another attribute can have. In that case, clients must always provide the attributes together.