Skip to content
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

[BUG] Replacing an existing Api resource operation #6913

Open
Prometee opened this issue Jan 12, 2025 · 0 comments
Open

[BUG] Replacing an existing Api resource operation #6913

Prometee opened this issue Jan 12, 2025 · 0 comments

Comments

@Prometee
Copy link

API Platform version(s) affected: 4.0.14 and maybe previous version such as 3.x

Description

Using Sylius Api Bundle, defining an existing Api resource operation when the same name is not replacing the old operation.

How to reproduce

Given I use Sylius.
And sylius/api-bundle the bundle is defining Api Resources using XML file format.
And I want to modify an existing Api resource operation such as sylius_api_shop_customer_post .
And I edit this api resource operation via an app file config/api_platform/Customer.yaml.
And I change the input class of this operation.
When I test this operation.
Then the modified input class must be used.
And this modified api resource operation should be replacing the previous one.

See this repository branch diff to test it : Sylius/Sylius-Standard@2.0...Prometee:Sylius-Standard:api-resource-remove-fields.

Exemple debugging the operation:
image
We can see 3 collections during the first command step:

  • [0] is the sylius/api-bundle defined Customer admin operations.
  • [1] is the sylius/api-bundle defined Customer shop operations.
  • [2] is the app defined Customer shop operation.

when ResourceMetadataCollection->getOperation('sylius_api_shop_customer_post')is called it returns the first operation found among those 3 collections and the Sylius shop one will be returned instead of the overwritten one from the app config file.

Possible Solution

\ApiPlatform\Metadata\Resource\ResourceMetadataCollection is iterating over each available metadata collections coming from various files (XML, YAML, PHP attributes). The classical order of iteration is from files contains in bundles to the app ones (https://github.com/Sylius/Sylius-Standard/blob/2.0/config/packages/api_platform.yaml#L4-L6).

What we can imagine here is to revert the iterator to get the overwritten collection.

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

No branches or pull requests

1 participant