Soit c'est Symfony qui a un gros beug soit c'est moi qui ne comprend pas ! Pourtant je reproduis findelement leur code source mais je n'ai pas le résultat voulu !! Alors je veux ajouter un point de terminaison OpenApi via un decorateur de service ! La documentation est ici https://api-platform.com/docs/main/core/openapi/. C'est pourtant simple. Il suffit de creer une classe qui etend de la OpenApiFactoryInterface, par exemple:
<?php
namespace App\OpenApi;
use ApiPlatform\OpenApi\Factory\OpenApiFactoryInterface;
use ApiPlatform\OpenApi\OpenApi;
use ApiPlatform\OpenApi\Model;
class OpenApiFactory implements OpenApiFactoryInterface
{
private $decorated;
public function __construct(OpenApiFactoryInterface $decorated)
{
$this->decorated = $decorated;
}
public function __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(),
[new Model\Parameter('fields', 'query', 'Fields to remove of the output')]
))
));
$openApi = $openApi->withInfo((new Model\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([new Model\Server('https://foo.bar')]);
return $openApi;
}
}
Et de l'ajouter en tant que service
# api/config/services.yaml
App\OpenApi\OpenApiFactory:
decorates: 'api_platform.openapi.factory'
arguments: [ '@App\OpenApi\OpenApiFactory.inner' ]
autoconfigure: false
Ce que je veux
Je dois avoir un point de terminaison /api/grumpy_pizzas/{id} sur mon interface swagger comme sur l'image https://cjoint.com/c/LKnvuMs8h5Q. Mais il ne se passe rien !!! Où est-ce que j'ai foré ???
Versions:
PHP: 8.1.10
Symfony: 5.3
api platform: 3.1 également testé avec la 2.6.6