I have a JSON PATCH endpoint in my API, but I don't want to allow all properties to be edited and eventually need to do specific actions when a property has changed.
I am having some trouble finding the best solution to achieve this.
Running NET Core 3.1.
Example of the object I have:
{
"id": "string",
"name": "string",
"type": "string",
"fields": [
{
"name": "string",
"label": "string",
"type": "Unknown",
"description": "string",
"required": true,
"defaultValue": "string",
"allowedValues": [
"string"
]
}
]
}
Example:
- Do not allow the id to be changed.
- When a field is changed to required, then defaultValue should be set as well.
- If type as specific value, then allowedValues cannot be empty and if defaultValue is set as well, then this defaultValue should be part of alllowedValues.
- etc.
So first is defining the rules for what is allowed to do and what not.
For that part I can manage most of it I think with defining Rules with FluentValidation. But the hard part is to figure out, which fields actually have changed. Mainly in the fields array. Any suggestions how to get that?
Second I want to do certain actions if a property has changed, but only if the property has changed.
Any suggestions how to best achieve this?
Edit: Ideally a C# alternative to this package: json-patch-rules.