core icon indicating copy to clipboard operation
core copied to clipboard

SerializedName and other name converters are not applied in JSON-LD context serialization

Open kriswillis opened this issue 3 years ago • 1 comments

API Platform version(s) affected: 2.6.8

Description
Properties annotated with #[SerializedName] have their original name in the output of /api/contexts/Entity, other name converters are also not applied.

How to reproduce Configure camel case to snake case name converter…

# /config/packages/api_platform.yaml
api_platform:
    name_converter: 'Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter'

Create an ApiResource that has camel case properties and/or properties annotated with #[SerializedName]

#[ApiResource]
class Person
{
    #[ApiProperty(identifier: true)]
    private int $id;

    private string $familyName;

    private string $givenName;

    #[SerializedName('date_of_birth')]
    private DateTime $dob;

    #[Ignore]
    private bool $visible = true;
}

Query the API for the context…

# curl https://127.0.0.1:8000/api/contexts/Person -H 'Accept: application/ld+json' | jq
{
  "@context": {
    "@vocab": "https://127.0.0.1:8000/api/docs.jsonld#",
    "hydra": "http://www.w3.org/ns/hydra/core#",
    "familyName": "Person/familyName",
    "givenName": "Person/givenName",
    "dob": "Person/dob"
  }
}

CamelCaseToSnakeCaseNameConverter is not applied to familyName and givenName, nor is #[SerializedName] applied to dob. Interestingly, the #[Ignore] annotation is applied to the visible property.

kriswillis avatar May 13 '22 12:05 kriswillis

And this also probably doesn't work within OpenApi.

soyuka avatar Sep 16 '22 09:09 soyuka

This bug is targeting 2.7, as API Platform 3.2 is out, version 2.7 has reached end of life. Therefore we'll close this issue.

We recommend to upgrade to API Platform 3.0, Les-Tilleuls.coop can offer paid support to help or even migrate your projects if they have tests.

We want to fund a Long Term Stable version of API Platform, if you or your organization would like to contribute to LTS support, please visit our Open Collective crowdfunding.

soyuka avatar Oct 17 '23 09:10 soyuka