Open LeeJump24 opened 2 years ago
Thanks for opening this issue, definitely something I need to add.
So there's an upcoming clarification in the JSON:API spec, that the links
object is only meant for use for JSON:API links. See this PR: https://github.com/json-api/json-api/pull/1691
If that gets merged and tagged, this issue will need to close - as adding links to a relationship object would go against the spec.
Seems to me that it is possible to define extension links, but I don't know for sure. Example:
{
"links": {
"myExtension:someLink": "https://example.com"
}
}
I've commented on the JSON:API PR to raise this as something that might need addressing.
I would recommend discussing specific use cases for linkage rather than discussing it in general. Looking at the example given in the initial post, it seems to be a link to a JSON:API document. That one fits well with the intent of links
member. I feel in that case the problem is trying to model two different relationships as a single one.
In your example you have two relationships:
questions
: to-manyfirstQuestion
: to-oneThe use case could be solved by modelling them as independent relationships each having a related
and self
links:
"relationships": {
"questions": {
"links": {
"related": "http://localhost/api/v1/surveys/4b732db9-48da-43c9-bec0-6df2dc7dcbe3/questions",
"self": "http://localhost/api/v1/surveys/4b732db9-48da-43c9-bec0-6df2dc7dcbe3/relationships/questions"
}
},
"firstQuestion": {
"links": {
"related": "http://localhost/api/v1/surveys/4b732db9-48da-43c9-bec0-6df2dc7dcbe3/firstQuestion",
"self": "http://localhost/api/v1/surveys/4b732db9-48da-43c9-bec0-6df2dc7dcbe3/relationships/firstQuestion"
}
}
}
This has multiple benefits:
links
object is not needed.firstQuestion
the same as the client could request inclusion of any other relationship.
Is it possible to add a link to a relationship? So add a link to the
firstQuestion
I'm not an expert on the spec but reading https://jsonapi.org/format/#document-resource-object-relationships sounds like it should be allowed? We can add extra links to other link objects.
Full example