-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[HttpKernel] Create #[Serialize] Attribute to serialize Controller Result
#49518
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
base: 8.1
Are you sure you want to change the base?
Conversation
#[SerializedResponse] Attribute to serialize Controller Result#[SerializedResponse] Attribute to serialize Controller Result
8e54594 to
9e16d8c
Compare
a30ee49 to
06087b9
Compare
#[SerializedResponse] Attribute to serialize Controller Result#[Serialized] Attribute to serialize Controller Result
#[Serialized] Attribute to serialize Controller Result#[Serialize] Attribute to serialize Controller Result
| * Controller tag to serialize response. | ||
| */ | ||
| #[\Attribute(\Attribute::TARGET_METHOD)] | ||
| class Serialize |
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.
indeed, others attribute are prefixed with As when they describe more the config of the class (AsCommand or AsMessageHandler)
here it is like a mapping/transformation, perhaps like your other PR #49138 MapResponse
src/Symfony/Component/HttpKernel/EventListener/SerializeControllerResultListener.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/HttpKernel/EventListener/SerializeControllerResultListener.php
Show resolved
Hide resolved
src/Symfony/Component/HttpKernel/EventListener/SerializeControllerResultListener.php
Outdated
Show resolved
Hide resolved
9eea8e6 to
9d1fb32
Compare
|
This test is failing https://github.com/symfony/symfony/actions/runs/4272061115/jobs/7436960556#step:7:8239 You probably have to add |
|
yes, thanx, it was added in #49138. I've not added it here to prevent merge conflicts. Also I want extend functional tests added in mentioned PR with new Attribute |
9d1fb32 to
3213f4b
Compare
fbc4eae to
ca0b60d
Compare
9845ae5 to
f350273
Compare
|
For what it's worth, I'm personally not convinced we should merge this. The reason is that the resulting behavior is very limited and resorting to explicit code comes very quickly - as soon as one needs more precise control over the resulting response for example. In the end, this saves two/three lines that are legit to have in a controller/similar to me. |
|
Exactly, this can save few lines in the Controller and reduce boilerplate. Of course it can't cover all needs for an every project, but same applicable for other stuff provided by Framework. 80/20 rule in action. We have few microservices that uses only We can go further and build OpenApi documentation based on Controller return type + Attribute existence via NelmioApiDocBundle. It will reduce even more boilerplate code for some projects. |
|
Rebased, renamed @nicolas-grekas please review 🙏 |
3c9a9b6 to
490a4ad
Compare
|
I've rebased PR one more time + fixed tests + actualized changelog. And as I've already mentioned - this feature needed not only for reducing boilerplate of serialization but also for simplification of the OpenApi spec generation via NelmioApiDocBundle. They already successfully adopted |
60f3583 to
cd02229
Compare
cd02229 to
ca9e6c5
Compare
|
rebased above 8.1, fixed conflicts, actualized tests (including functional) ✔️ |
#[Serialize(code: 200, headers: [], serializationContext: [])]Allows automatically serialize Controller Result to format based on Request format.Usage example 🔨
Todo
#[MapRequestPayload]and#[MapQueryString]to map Request input to typed objects #49138 will be merged