Description
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.
Andsylius/api-bundle
the bundle is defining Api Resources using XML file format.
And I want to modify an existing Api resource operation such assylius_api_shop_customer_post
.
And I edit this api resource operation via an app fileconfig/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:
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.