Description
Hi! First of all, thanks for this excellent library. It will definitely save a lot of boilerplate CRUD code for implementing a JSONAPI compliant API.
According to the JSONAPI spec, regarding updating attributes through a PATCH request:
Any or all of a resource’s attributes MAY be included in the resource object included in a PATCH request. 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. The server MUST NOT interpret missing attributes as null values.
It seems as though this behavior isn't quite happening here.
Initial data:
{
"data": {
"type": "todo-items",
"id": "47",
"attributes": {
"description": "At qui dolores pariatur sint.",
"ordinal": 1,
"guid-property": "4180c2da-f7da-4579-bec1-62fab3edbfa6",
"created-date": "2017-05-12T10:50:18.791782",
"achieved-date": null
},
"relationships": {
"owner": {
"links": {
"self": "http://localhost:5000/api/v1/todo-items/47/relationships/owner",
"related": "http://localhost:5000/api/v1/todo-items/47/owner"
}
},
"assignee": {
"links": {
"self": "http://localhost:5000/api/v1/todo-items/47/relationships/assignee",
"related": "http://localhost:5000/api/v1/todo-items/47/assignee"
}
},
"collection": {
"links": {
"self": "http://localhost:5000/api/v1/todo-items/47/relationships/collection",
"related": "http://localhost:5000/api/v1/todo-items/47/collection"
}
}
}
},
"meta": {
"total-records": 0
}
}
Example request:
PATCH api/v1/todo-items/47 HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json
{
"data": {
"type": "todo-items",
"id": "47",
"attributes": {
"description": "Test description"
}
}
}
Expected result:
{
"data": {
"type": "todo-items",
"id": "47",
"attributes": {
"description": "Test description",
"ordinal": 1, // original value is kept
"guid-property": "4180c2da-f7da-4579-bec1-62fab3edbfa6",
"created-date": "2017-05-12T10:50:18.791782",
"achieved-date": null
},
// additional relationships and meta data
}
Actual result:
{
"data": {
"type": "todo-items",
"id": "47",
"attributes": {
"description": "Test description",
"ordinal": 0, // original value is overwritten
"guid-property": "4180c2da-f7da-4579-bec1-62fab3edbfa6",
"created-date": "2001-01-01T00:00:00",
"achieved-date": null
},
// additional relationships and meta data
}
The attributes that were not included in the patch request (e.g., ordinal
and created-date
) appear to be reset to their default values for their respective types. A quick look at the source code shows that in DefaultEntityRepository.UpdateAsync()
method it's looping through ALL of the attributes in the RequestEntity
, not just the ones that were included in the PATCH.
If this is something that should be fixed, it would seem that there needs to be a way in the deserialization process to "flag" which attributes were included in the request. Not sure what the best approach would be to implement that, though.