api-platform / core

The server component of API Platform: hypermedia and GraphQL APIs in minutes
https://api-platform.com
MIT License
2.43k stars 863 forks source link

Name converter configuration changes Symfony serializer globally, affecting whole project, not only API Platform managed part. #6101

Open vuryss opened 8 months ago

vuryss commented 8 months ago

API Platform version(s) affected: 3.2

Description
I'm trying to integrate API Platform in existing project, which already has multiple APIs defined. Those APIs all depend on Symfony serializer, and some of them use different case for the json fields - some camelCase, some snake_case. For the new API we decided to go with API Platform, and we wanted all fields to be snake_case. However setting the name_converter according to the docs overwrites the global Symfony Serializer metadata-aware name converter and sets the snake_case as a fallback, making all of the existing APIs outside API Platform snake_cased.

I've tried overwriting the api_platform.name_converter via configuration, but it's hard defined in a MetadataAwareNameConverterPass and I cannot do anything about it inside the config file.

When setting a configuration specific to API Platform I expect it not to affect globally the rest of the project.

How to reproduce
Use serializer in any other place outside the API Platform while changing the name_converter in api_platform config.

Possible Solution
Allow using separate Serializer Name Converter specific for API Platform instead of modifying globally the default serializer name converter.

stale[bot] commented 6 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

soyuka commented 4 months ago

I don't understand your name converter should end-up being injected inside https://github.com/symfony/symfony/blob/1f90bc30c32b375ed2cdc3234f56d26b8b99cb53/src/Symfony/Component/Serializer/NameConverter/MetadataAwareNameConverter.php.

About the serializer being altered, maybe that's because of the serializer alias https://github.com/api-platform/core/blob/main/src/Symfony/Bundle/Resources/config/api.xml#L12 ? @dunglas is this intended?