I am trying to build an API in rails using JSON API specification
My User model has change objects associated with them. For example, user can have the following change:
{
id: 10,
type: 'changes',
diffs: [
{
subject: 'email',
from: 'old@example.org',
to: 'new@example.org'
},
{
subject: 'tags',
from: []
to: [{ id: 1, type: 'tags', label: 'Ruby' }]
}
]
}
As you can see the diffs
property contains an array of change differences and the second difference is an array of objects difference. I would want to modify this format (if possible) so it will conform JSON API specification. Like this:
{
subject: 'tags',
from: []
to: [{ id: 1, type: 'tags' }]
}
And put the tag's attributes into the included section:
included: [
{
id: 1,
type: 'tags',
attributes: { label: 'Ruby' }
}
]
Question: differences is an array of objects (not records, they do not have ID) which contain fields with records. Is possible to format the response so deeply nested records (like tags in my case) will be reference to the records in the included section?
I would want to use fast_jsonapi gem