-
-
Notifications
You must be signed in to change notification settings - Fork 933
Description
API Platform version(s) affected: 3.1.6
Description
After upgrading from version 3.0.2 caching in ApiPlatform\Metadata\Property\Factory\CachedPropertyMetadataFactory
is inconsistent. When metadata is obtained through api_platform.metadata.property.identifier_metadata_factory
decorators chain produces different results from metadata obtained from api_platform.metadata.property.metadata_factory
.
How to reproduce
We are decorating api_platform.metadata.property.metadata_factory
and api_platform.metadata.property.identifier_metadata_factory
because our identifiers are interfaces. We need to define implementation in Properties.xml
like this:
<property resource="App\Payment\Purchase" name="purchaseId" identifier="true">
<types>
<type>App\Payment\ValueObject\HashPurchaseId</type>
</types>
</property>
Our decorator will fetch this data from parent decorator \ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface
. Then we return modified \ApiPlatform\Metadata\ApiProperty
, from which API Platform can determine the implementation of the PaymentId
interface.
This does not work anymore as when api_platform.metadata.property.identifier_metadata_factory
chain is called firts it is chached without type from Properties.xml
.
$apiProperty = $this->decorated->create($resourceClass, $property, $options) ;
// $apiProperty->getTypes() === null
Possible Solution
If api_platform.metadata.property.identifier_metadata_factory
has api_platform.metadata.property.identifier_metadata_factory.xml
as first service in chain it will work for us. It is because api_platform.metadata.property.metadata_factory
has this factory first in decorator chain too.
But it can break other features.
Additional Context
I believe the behaviour should be the same between different decorator chains as they are cached by same cache key.
As a workaround we use \ApiPlatform\Metadata\Extractor\XmlPropertyExtractor
directly in our decorator.
Minimal working example: https://github.com/BPavol/api-platform-cache-issue