api-platform / core

The server component of API Platform: hypermedia and GraphQL APIs in minutes
https://api-platform.com
MIT License
2.45k stars 877 forks source link

ExtractorPropertyMetadataFactory creates ApiProperty with builtinTypes being string instead of Type #6602

Closed camilledejoye closed 2 days ago

camilledejoye commented 2 months ago

API Platform version(s) affected: 3.3.11 (didn't checked earlier versions)

Description
The ExtractorPropertyMetadataFactory creates metadata with invalid builtin types when updating the "parent metadata" built by the next factory in the chain.

How to reproduce
Have an ApiResource with a typed property and setup the chain of factories so that the ExtractorPropertyMetadataFactory delegates to another one, like PropertyInfoPropertyMetadataFactory.

Possible Solution
Update ExtractorPropertyMetadataFactory::update(ApiProperty $propertyMetadata, array $metadata): ApiProperty to convert the builtin types found in $metadata (the one extracted) into Type objects. This is already done but only when there was no "parent metadata": https://github.com/api-platform/core/blob/7110dc665bde47b15dcfe8b1e3198427f8a78938/src/Metadata/Property/Factory/ExtractorPropertyMetadataFactory.php#L62-L64

Additional Context
Output of the terminal with the error we originally got: image

To reproduce this, it's also probably needed to add a validation constraint on the property. To be honest, I didn't checked.

After identifying that the issue came from the extractor factory, validating the possible solution by updating the method directly in the "vendor" directory.
We just implemented a decorator around the extractor we use to convert the types if needed.

stale[bot] commented 1 week ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.