Last active
January 21, 2025 08:54
-
-
Save llupa/008b93e6f18b803648a278e9930f66dd to your computer and use it in GitHub Desktop.
selectively_hide_or_show_some_of_the_endpoints.php
This file contains hidden or 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 | |
| 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