Skip to content

Instantly share code, notes, and snippets.

@llupa
Last active January 21, 2025 08:54
Show Gist options
  • Select an option

  • Save llupa/008b93e6f18b803648a278e9930f66dd to your computer and use it in GitHub Desktop.

Select an option

Save llupa/008b93e6f18b803648a278e9930f66dd to your computer and use it in GitHub Desktop.
selectively_hide_or_show_some_of_the_endpoints.php
<?php
use ApiPlatform\OpenApi\Model\Paths;
use ApiPlatform\State\ProcessorInterface;
use ApiPlatform\Symfony\Bundle\SwaggerUi\SwaggerUiProcessor as DecoratedProcessor;
#[AsDecorator('api_platform.swagger_ui.processor')]
readonly class SwaggerUiProcessor implements ProcessorInterface
{
public function __construct(private DecoratedProcessor $decorated)
{
}
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): Response
{
if (getenv('SKIP') {
return $this->decorated->process($data, $operation, $uriVariables, $context);
}
/** @var OpenApi $data */
$paths = $data->getPaths();
$finalPaths = new Paths;
// pseudo-solution, adapt at your convenicence
foreach ($paths->getPaths() as $path => $pathItem) {
if ($conditionToSkip) {
continue;
}
$finalPaths->addPath($path, $pathItem);
}
$data = $data->withPaths($paths);
return $this->decorated->process($data, $operation, $uriVariables, $context);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment