-
-
Notifications
You must be signed in to change notification settings - Fork 980
Description
API Platform version(s) affected: >=4.1
Description
When using the command api:openapi:export you can specify a spec_version. if i'am not wrong i think we can do it from browser by passing the query param ?spec_version=xxx
For some reasons, i need to generate documentation with differents spec versions
Because the generation is cached.
How to reproduce
Navigate on /api url to generate your api documentation (spec-version=3.1 by default)
Execute the command api:openapi:export ---spec-version=3.0
Your documentation will be generated with the cache so you will get a 3.1 spec instead of 3.0
Possible Solution
Fortunately, the method CachedPropertyMetadataFactory::create generate the cache key by considering the options parameter.
One possible solution will be to transport the spec_version on options ?
On my projet, i created a decorator which works as intended.. but i can contribute to suggest a native implementation :
#[AsDecorator(decorates: 'api_platform.metadata.property.metadata_factory.cached')]
final class CachedPropertyMetadataFactory implements PropertyMetadataFactoryInterface
{
public function __construct(#[AutowireDecorated]
private PropertyMetadataFactoryInterface $decorated,
private OpenApiContext $openApiContext
) {
}
public function create(string $resourceClass, string $property, array $options = []): ApiProperty
{
$options['spec_version'] = $this->openApiContext->specVersion;
return $this->decorated->create($resourceClass, $property, $options);
}
}