-
-
Notifications
You must be signed in to change notification settings - Fork 251
Open
Labels
questionFurther information is requestedFurther information is requested
Description
Consider a simple struct with two nullable string fields:
type Foo struct {
A *string `json:"a"`
B *string `json:"b"`
}
It is evidently impossible to set these fields to nil via a PATCH with application/merge-patch+json content type. For instance, the following request will throw a 422 with a message "expected required property a to be present".
curl --request PATCH \
--url http://localhost:8888/foo/1 \
--header 'Accept: application/json, application/problem+json' \
--header 'Content-Type: application/merge-patch+json' \
--data '{
"a": null
}'
This seems like a bug in merge patch computation: the PUT body in the autogenerated GET/PUT sequence omits the a field altogether instead of setting a: null as expected.
The only way to set a to nil appears to be via a PUT of the full struct or via a json-patch (not merge-patch):
curl --request PATCH \
--url http://localhost:8888/foo/1 \
--header 'Accept: application/json, application/problem+json' \
--header 'Content-Type: application/json-patch+json' \
--data '[
{ "op": "replace", "path": "/a", "value": null }
]
This came as an unfortunate surprise as our front-end client started making use of PATCH requests.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested