Imagine a JSONApi resource that keeps track of all data changes by saving the old and new value of each property that has changed.
A simple record that should be compliant to JSONApi might look like this:
{
"id": "1",
"type": "auditlog",
"attributes": {
"diff": [
{
"property": "name",
"old": "Old Name",
"new": "New Name"
}
]
},
"relationships": {
"performedOn": {
"data": {
"id": "2",
"type": "customer"
}
},
"performedBy": {
"data": {
"id": "3",
"type": "user"
}
}
}
}
I am not sure how to express a change where “old” and “new” is not a simple value but a relationship. The following is definitely not valid JSONApi (at least not in a way that enables clients to automatically fetch “old” and “new” data…)
{
[...]
"attributes": {
"diff": [
{
"property": "status",
"old": {
"id": "4",
"type": "customerStatus"
},
"new": {
"id": "5",
"type": "customerStatus"
}
}
]
}
[...]
}
How would you do this?
Thanks!