Created
October 15, 2024 10:14
-
-
Save vincentchalamon/5dce63053b8c9cbe45150dfedbf9ca56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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