core icon indicating copy to clipboard operation
core copied to clipboard

`api_platform.name_converter` is applied to Symfony serializer default

Open VincentLanglet opened this issue 3 months ago • 4 comments

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 ?

VincentLanglet avatar Nov 22 '25 09:11 VincentLanglet

cc @mbeccati since you made https://github.com/api-platform/core/pull/7365

VincentLanglet avatar Nov 22 '25 10:11 VincentLanglet

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.

mbeccati avatar Nov 22 '25 11:11 mbeccati

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.

VincentLanglet avatar Nov 22 '25 11:11 VincentLanglet

Sure, I understand. Looks like a feature request and I will leave it to the project team :-)

mbeccati avatar Nov 22 '25 12:11 mbeccati