You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to request the addition of a feature that allows developers to override the OpenAPI documentation via a YAML file instead of using the OpenApiFactory class. This would make the process easier and more readable. Currently, overriding the OpenAPI documentation requires the use of the OpenApiFactory class, which can be less intuitive and harder to manage for complex configurations. By enabling YAML-based overrides, developers can leverage the simplicity and readability of YAML to define their custom OpenAPI documentation.
Example
Here is a simple example of how this feature could be implemented.
Current Method (Using OpenApiFactory Class):
<?phpnamespaceApp\OpenApi;
useApiPlatform\OpenApi\Factory\OpenApiFactoryInterface;
useApiPlatform\OpenApi\OpenApi;
useApiPlatform\OpenApi\Model;
class OpenApiFactory implements OpenApiFactoryInterface
{
publicfunction__construct(privateOpenApiFactoryInterface$decorated)
{
}
publicfunction__invoke(array$context = []): OpenApi
{
$openApi = $this->decorated->__invoke($context);
$pathItem = $openApi->getPaths()->getPath('/api/grumpy_pizzas/{id}');
$operation = $pathItem->getGet();
$openApi->getPaths()->addPath('/api/grumpy_pizzas/{id}', $pathItem->withGet(
$operation->withParameters(array_merge(
$operation->getParameters(),
[newModel\Parameter('fields', 'query', 'Fields to remove of the output')]
))
));
$openApi = $openApi->withInfo((newModel\Info('New Title', 'v2', 'Description of my custom API'))->withExtensionProperty('info-key', 'Info value'));
$openApi = $openApi->withExtensionProperty('key', 'Custom x-key value');
$openApi = $openApi->withExtensionProperty('x-value', 'Custom x-value value');
// to define base path URL$openApi = $openApi->withServers([newModel\Server('https://foo.bar')]);
return$openApi;
}
}
In this example, the custom OpenAPI modifications are specified in a YAML file, which is then injected into the OpenApiFactory class. This approach enhances readability and maintainability, especially for large-scale projects with complex OpenAPI customizations.
The text was updated successfully, but these errors were encountered:
It still works with Api Platform Core 3.x as openapiContext attribute. I am using it extensively however as deprecated it will be removed in AP Core 4.x so one would have to face it in the future.
It seems that here is no elegant way to implement openapi support in the shema-generator, ex. ApiPlatform\OpenApi\Model classes implements fluent and immutable interface that is not too friendly for denormalizers so it needs manual explicit initialization.
Currently, overriding the OpenAPI documentation requires the use of the OpenApiFactory class, which can be less intuitive and harder to manage for complex configurations.
Maybe more clearly would be with some configurator pattern for ApiResource by decorating ResourceMetadataCollectionFactoryInterface.
Description
I would like to request the addition of a feature that allows developers to override the OpenAPI documentation via a YAML file instead of using the OpenApiFactory class. This would make the process easier and more readable. Currently, overriding the OpenAPI documentation requires the use of the OpenApiFactory class, which can be less intuitive and harder to manage for complex configurations. By enabling YAML-based overrides, developers can leverage the simplicity and readability of YAML to define their custom OpenAPI documentation.
Example
Here is a simple example of how this feature could be implemented.
Current Method (Using OpenApiFactory Class):
Proposed Method (Using YAML File):
Example Configuration in services.yaml:
In this example, the custom OpenAPI modifications are specified in a YAML file, which is then injected into the OpenApiFactory class. This approach enhances readability and maintainability, especially for large-scale projects with complex OpenAPI customizations.
The text was updated successfully, but these errors were encountered: