Skip to content

fix(jsonld): genId false should work with embeded resources #7219

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

Merged
merged 1 commit into from
Jun 19, 2025

Conversation

soyuka
Copy link
Member

@soyuka soyuka commented Jun 16, 2025

Q A
Branch? 4.1
License MIT

When a class is a resource genId had no impact. Thanks to this patch you can use genId false to get the embeded result even if the resource is declared.

Example:

#[ApiResource(operations: [])]
class AggregateRating
{
    public function __construct(
        #[ApiProperty(iris: ['https://schema.org/ratingValue'])] public float $ratingValue,
        #[ApiProperty(iris: ['https://schema.org/ratingCount'])] public int $ratingCount,
    ) {
    }
}

#[Get(provider: [self::class, 'getData']]
class Product
{
    public function __construct(public string $id, #[ApiProperty(genId: false)] public AggregateRating $aggregateRating)
    {
    }

    public static function getData(Operation $operation, array $uriVariables = [], array $context = []): self
    {
        return new self('1', new AggregateRating(2, 3));
    }
}

Outputs:

{
    "@context": "/contexts/GenIdFalse",
    "@id": "/gen_id_falsy",
    "@type": "GenIdFalse",
    "id": "1",
    "aggregateRating": {
        "@type": "AggregateRating",
        "ratingValue": 2,
        "ratingCount": 3
    }
}

TODO: Ignore on attribute still shows in JSON-LD context (edit could not reproduce it works)

@soyuka soyuka force-pushed the fix/genid-resource-embed branch 4 times, most recently from 40fcfac to 8641e9e Compare June 19, 2025 09:56
@soyuka soyuka force-pushed the fix/genid-resource-embed branch from 8641e9e to d760ce2 Compare June 19, 2025 10:07
@soyuka soyuka merged commit 34a0d54 into api-platform:4.1 Jun 19, 2025
108 of 111 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant