Skip to content

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
NoResponseMate added a commit to Sylius/Sylius that referenced this pull request Jun 30, 2025
…atform changes with usage of genId (#18196)

| Q               | A
|-----------------|-----
| Branch?         | 2.1
| Bug fix?        | yes
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | 
| License         | MIT

This PR fixes issue with APIP 4.1.17:
https://github.com/Sylius/Sylius/actions/runs/15963124014/job/45018806151#step:11:16,
after api-platform/core#7219.

Reference: api-platform/core#7261
<!--
 - Bug fixes must be submitted against the 1.14 or 2.0 branch
 - Features and deprecations must be submitted against the 2.1 branch
 - Make sure that the correct base branch is set

To be sure you are not breaking any Backward Compatibilities, check the
documentation:

https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html
-->


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Updated the Taxon API resource configuration to explicitly set the URL
generation strategy, which affects how URLs are generated for
Taxon-related API operations.

* **Style**
* Minor formatting adjustment in the XML property tag for channel price
history configuration (no impact on functionality).

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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