[HttpKernel] Create Attributes #[MapRequestPayload] and #[MapQueryString] to map Request input to typed objects#49138
Conversation
87eb66c to
a08be6b
Compare
#[MapQueryString and #[MapRequestContent] to map Request input to typed objects
#[MapQueryString and #[MapRequestContent] to map Request input to typed objects#[MapQueryString] and #[MapRequestContent] to map Request input to typed objects
078781e to
b3bbe43
Compare
|
It looks like your committer email is not associated with your Github account |
|
Was this a coincidence that we both did something similar or did you create this afterwards? |
b3bbe43 to
4e8cb8e
Compare
|
@OskarStark thanx, fixed now, please check @ruudk it is similar but has few differences comparing to your implementation. I've updated PR description to highlight the differences. BTW anybody know how to fix unrelated fabbot failure? |
|
this looks promising :)
what about deserializing errors vs. ValidationFailedException? Does either produce a 400 bad request? is only the latter i18n friendly? |
|
My idea was start from something like simple implementation in this PR and improve it later before 6.3 release.
|
4e8cb8e to
1b619a2
Compare
|
i like a simple implementation as first iteration, but i like http/i18n compatibility more ;) |
19069b1 to
052f625
Compare
|
Your PR also makes this one #47425 obsolete. |
052f625 to
25e7d70
Compare
|
I would use a separate exception, which builds on the |
cf31004 to
a2b5f96
Compare
|
Is the naming of attributes final, What about names suggested here ( |
|
Landing late to the discussion :hi: This PR overlaps some work I participate currently, so here are some feedbacks:
Most of these ideas are implemented in https://github.com/acsiomatic/http-payload-bundle (ping @renedelima) All of them can be done in further PR. I think the current PR presents no blockers regarding these ideas in this comment. |
We have a convention to help discovery that controller-related attributes should start with
"body" is not a word we use in the request object so this would be MapRequestContent. It's an open topic no my side. "payload" is also new vocabulary so we might prefer "content", which is a term we use already.
Which leads to the idea of adding
My suggestion for this: make the attribute non final. Then a preset is just a child attribute. We do something similar for DI-attributes and it works great. I left your other questions open for someone else :) |
src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/RequestPayloadValueResolver.php
Outdated
Show resolved
Hide resolved
@renanbr Have you seen Functional Tests which checks for Make class non-final is always easier than vise versa. Let's collect more feedback about all possible "child" implementation first and then remove |
src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/RequestPayloadValueResolver.php
Outdated
Show resolved
Hide resolved
I'd prefer removing the |
nicolas-grekas
left a comment
There was a problem hiding this comment.
please check tests, some failures look related to me
src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/RequestPayloadValueResolver.php
Outdated
Show resolved
Hide resolved
...y/Component/HttpKernel/Tests/Controller/ArgumentResolver/RequestPayloadValueResolverTest.php
Outdated
Show resolved
Hide resolved
...y/Component/HttpKernel/Tests/Controller/ArgumentResolver/RequestPayloadValueResolverTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/RequestPayloadValueResolver.php
Show resolved
Hide resolved
…String]` to map Request input to typed objects
nicolas-grekas
left a comment
There was a problem hiding this comment.
I just made some minor and final changes:
https://github.com/symfony/symfony/compare/50c06d123c1c0539a1e47cb202bce6d430247ff7..d987093a538c70fc4a2d01b046913a2820341699
|
Thank you @Koc. |
|
Note that if there are remaining topics to discuss (naming?), we're still in feature freeze so we can do any changes! |
|
@nicolas-grekas thanx! I'm fine with |



Yet another variation of how we can map raw Request data to typed objects with validation. We can even build OpenApi Specification based on this DTO classes using NelmioApiDocBundle.
Usage Example 🔧
#[MapRequestPayload]#[MapQueryString]Exception handling 💥
ConstraintViolationList.Comparison to another implementations 📑
Differences to #49002:
Differences to #49134:
$request->getContent()and$request->request->all()mappingDifferences to #45628:
$request->request->all()and$request->query->all()mappingBonus part 🎁
UnsupportedFormatExceptionwhich thrown when there is no decoder for a given format