-
-
Notifications
You must be signed in to change notification settings - Fork 874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(serializer): Guess uri variables with the operation and the data instead of hardcoding id #5546
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
Can you target 3.1 as this is a bug fix? |
@soyuka , done: the PR now targets 3.1. |
Thanks! Can you document this an provide an example in the official docs? It's been something I've wanted and worked with subresources in 2.6 but much harder to do in 3.0, in part because there's so few examples. |
I'll rebase that thanks! |
@tacman , it is already documented: https://api-platform.com/docs/core/subresources/ This PR simply allows to use an URI like |
This will be out friday |
thanks @Aerendir |
Well we're back on this as this can not work, I should've been more careful but this is not how things are supposed to work. Use IRIs or a custom normalizer if you need to do weird stuff. |
@soyuka , please, can you explain better? |
main
In a situation where these two conditions are true, also alternatively and not necessarily at the same time, the code will break:
account/{account}/resource/{resource}/sub_resource/{sub_resource}
id
(in the above example, the uri parameter issub_resource
)Why it breaks
In
ItemNormalizer:79
there is this todo:core/src/Serializer/ItemNormalizer.php
Lines 79 to 80 in ccef472
As you can see, the context passed to
$this->iriConverter->getIriFromResource()
(4th parameter) is hardcoded and always refers to the ID of the current denormalizing entity.This is not correct (and, in fact, there is also the todo to remember this fact) as this could break the code.