jsonapi-serializer
jsonapi-serializer copied to clipboard
relationshipLinks does not allow self links
The relationshipLinks option only allow related where the 1.0 specification allows both self and related.
possible section of code related to the issue https://github.com/SeyZ/jsonapi-serializer/blob/master/lib/serializer-utils.js#L162
1.0 specification section https://jsonapi.org/format/#document-resource-object-relationships
I cannot do the following and have "self" links:
let people = [
{
id: 10,
fname: 'aaa',
lname: 'bbb',
title: 'king',
subPerson: {
id: 12,
fname: 'ccc',
lname: 'ddd',
title: 'knight'
}
},
{
id: 11,
fname: 'eee',
lname: 'fff',
title: 'queen',
subPerson: {
id: 13,
fname: 'ggg',
lname: 'hhh',
title: 'jester'
}
}
];
let response = new JSONAPI('people', {
meta: { count: 2 },
attributes: ['fname', 'lname', 'title', 'subPerson'],
subPerson: {
ref: 'id',
//included: false,
attributes: ['fname', 'lname', 'title'],
relationshipLinks: {
self: function(record, current, parent) {
return '/api/jsonapi/people/' + current.id;
}
}
}
}).serialize(people);
I encountered this today. A temporary solution is to also have a related link.
This is a regression. self links in relationships were working in 3.4.3 but no longer seem to work in 3.6.6
After a little digging it appears that this is in fact a regression introduced by this commit:
https://github.com/SeyZ/jsonapi-serializer/commit/3d776ef46b3cb150d09c9d7efc209a5a7ecc7bc0
Starting in 3.6.1 of the library you can no longer have self links on their own which is definitely a bug.
@roycetech I created a PR that should fix this issue if you'd like to try it out.