Skip to content

Instantly share code, notes, and snippets.

@vincentchalamon
Created October 15, 2024 10:14
Show Gist options
  • Save vincentchalamon/5dce63053b8c9cbe45150dfedbf9ca56 to your computer and use it in GitHub Desktop.
Save vincentchalamon/5dce63053b8c9cbe45150dfedbf9ca56 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
namespace App\OpenApi;
use ApiPlatform\Core\OpenApi\Factory\OpenApiFactory as ApiPlatformOpenApiFactory;
use ApiPlatform\Core\OpenApi\Factory\OpenApiFactoryInterface;
use ApiPlatform\Core\OpenApi\OpenApi;
use ApiPlatform\Core\OpenApi\Model;
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
#[AsDecorator(decorates: ApiPlatformOpenApiFactory::class)]
final class OpenApiFactory implements OpenApiFactoryInterface
{
public function __construct(private OpenApiFactoryInterface $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')]
))
));
return $openApi;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment