Skip to content
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

[Question]: Is using #[Context(...)] supposed to be supported? #2402

Open
mathroc opened this issue Nov 28, 2024 · 3 comments
Open

[Question]: Is using #[Context(...)] supposed to be supported? #2402

mathroc opened this issue Nov 28, 2024 · 3 comments

Comments

@mathroc
Copy link

mathroc commented Nov 28, 2024

Version

4.33.4

Question

I implemented a Symfony normalizer that supports normalizing / denormalizing enum by their name when adding a #[Context('_nelmio_enum_force_names' => true)] attribute and I'm trying to get nelmio to generate a model with type = string and using the enum names for the values in this case.

I created an EnumModelDescriber that does the same thing as the one in NelmioBundleDocBundle but also acceptd UnitEnum when _nelmio_enum_force_names is true in the serialization context. But the context is empty even if I add the #[Context('_nelmio_enum_force_names' => true)] attribute on the property holding the enum.

Is this expected?

Additional context

No response

@DjordyKoert
Copy link
Collaborator

This is not currently supported 😞

@mathroc
Copy link
Author

mathroc commented Jan 6, 2025

Thank you for the reply @DjordyKoert . I see you labeled that as a good first issue. Depending on how much time it requires I may take a try at it. If you already know how it should be implemented, do you mind giving me some guideline / hints? 🙏

@DjordyKoert
Copy link
Collaborator

I think that this can be implemented by simply getting the class metadata as is done in various places already

https://github.com/search?q=repo%3Anelmio%2FNelmioApiDocBundle%20getMetadataFor&type=code

And then call ClassMetadataInterface->getAttributesMetadata() which returns array<string, AttributeMetadataInterface> with the key assuming to be the property name.

https://github.com/symfony/serializer/blob/ab913397b9aeee6d89277dded14fa8259dc1e46d/Mapping/AttributeMetadataInterface.php#L86

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants