Issue with the OpenAPI specification in the ApiResource annotation of API Platform

115 Views Asked by At

I am currently encountering an issue with the OpenAPI specification within the ApiResource annotation of API Platform. My environment is configured with API Platform version 3.2.4, Symfony 6.2.14, and PHP 8.2.10.

My objective is to extract the part of the ApiResource annotation that defines the OpenAPI specification. I aim to enhance the readability of my code, yet I prefer not to adopt an alternative approach outside the use of annotations. Previously, utilizing openapi_context allowed for this task in a straightforward manner, but this option has been deprecated.

Here's an example of my resource code:

#[ApiResource(
    shortName: 'Demande',
    operations: [
        new Get(
            openapi: PostDemandeOpenapi::class /* part to be extracted */,
            provider: DemandeItemProvider::class
        ),
        // ...
    ]
)]
final class DemandeResource {
    // ...
}

Additionally, here's an example of PostDemandeOpenapi.php:

final class PostDemandeOpenapi
{
    public function __invoke(): Operation {
        // ... logic to create and return an instance of Operation ...
    }
}

While the above code does not generate an error, the OpenAPI specification is not being considered. It's important to note that the openapi annotation in ApiResource expects a type of bool|Operation, but Operation is a final class, meaning it cannot be inherited.

If anyone has ideas or suggestions to resolve this issue, I would greatly appreciate any assistance. Thank you in advance!

I have attempted to extract the OpenAPI specification from the ApiResource annotation in API Platform. I initially tried using the openapi_context option, but this method has been deprecated. As an alternative, I explored using a separate class (PostDemandeOpenapi.php) to define the OpenAPI specification. While the code does not result in errors, the OpenAPI specification is not being recognized.

I've also researched API Platform documentation and related forums to find any potential solutions or insights into this issue.

0

There are 0 best solutions below