`api_platform.name_converter` is applied to Symfony serializer default
API Platform version(s) affected: 4.2.6
Description
Hi @soyuka, I feel like the issue https://github.com/api-platform/core/issues/6101 is not totally resolved.
When I set
api_platform.name_converter: serializer.name_converter.camel_case_to_snake_case
it still use snake case for the default serializer, even if I use it in a non-api-platform context.
I would expect the config api_platform.name_converter to only impact api platform.
Currenly it basically conflict with the framework.serializer.name_converter option...
Which means that if other bundles (like symfony/ai in my case) uses the default serializer, it's impacted by the api_platform config !
How to reproduce
- Set
api_platform.name_converter: serializer.name_converter.camel_case_to_snake_case - Use the default serializer somewhere else
- it will use snake case instead of default behavior
Possible Solution
Maybe named serializers could be used to defined a specific serializer for api_platform ?
https://symfony.com/doc/current/serializer.html#named-serializers
Or maybe, rather than provider a name_converter option, it would be better to have a serializer option ?
cc @mbeccati since you made https://github.com/api-platform/core/pull/7365
Well, before my PR, the name converter was applied on all the named serializers, not just the default one. Of course, API platform could build its own serializer instead? Not up to me to decide.
TBH I prefer this behaviour in my current projects as I want the default serializer to be consistent with API Platform. Whenever I need different settings, I use named serializers.
TBH I prefer this behaviour in my current projects as I want the default serializer to be consistent with API Platform.
There is two different config property:
-
api_platform.name_converter -
framework.serializer.name_converter
If you want the same behavior you "just" have to pass the same name_converter at the two places, but it should be possible to use different one IMHO.
Whenever I need different settings, I use named serializers.
I do it too, but it's not possible when the "default" serializer is used by another bundle.
Sure, I understand. Looks like a feature request and I will leave it to the project team :-)