loopback-component-jsonapi
loopback-component-jsonapi copied to clipboard
Nested request returns object with incorrect "self" relation
If I make a request to http://localhost:3000/api/users/1/posts
, I get the following response:
{
"links": {
"self": "http://localhost:3000/api/users/1/posts" // correct
},
"data": [
{
"type": "user", // this should be "post"
"relationships": {
"user": {
"links": {
"related": "http://localhost:3000/api/posts/99/user" // correct
}
}
},
"id": "99",
"attributes": {
"some": "attributes"
},
"links": {
"self": "http://localhost:3000/api/users/99" // this should be "http://localhost:3000/api/posts/99"
}
}
]
}
Note the error in the URL: "http://localhost:3000/api/users/99"
The id segment is correct (this is the self link for post 99), but the model-name segment refers to the parent resource, "users", instead of the child resource, "posts"
I'm confused by this. It's the self link in the "user" entry.
I think that part of the issue is that the type
key in this example is also incorrect @csprocket777. A request to http://localhost:3000/api/users/1/posts should only return data
with "type": "post"
. That is probably the reason why the self link is getting generated incorrectly, it is probably getting built from pluralising the type.
yeah as @markstuart says its not just the "self"
but also the "type"
that's wrong. I've updated the issue text to highlight this