From 3d4af0c797f1bdc4e45dea28cea0a56627601ba2 Mon Sep 17 00:00:00 2001 From: Jakov Knezovic Date: Thu, 15 Jan 2026 14:04:33 +0100 Subject: [PATCH 1/6] NGSTACK-1017 add openapi factory decorator and openapi processor interface --- src/OpenApi/Factory/OpenApiFactory.php | 36 +++++++++++++++++++ .../Processor/OpenApiProcessorInterface.php | 21 +++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/OpenApi/Factory/OpenApiFactory.php create mode 100644 src/OpenApi/Processor/OpenApiProcessorInterface.php diff --git a/src/OpenApi/Factory/OpenApiFactory.php b/src/OpenApi/Factory/OpenApiFactory.php new file mode 100644 index 0000000..48c9d5f --- /dev/null +++ b/src/OpenApi/Factory/OpenApiFactory.php @@ -0,0 +1,36 @@ + $processors + */ + public function __construct( + private OpenApiFactoryInterface $decorated, + private iterable $processors, + ) {} + + public function __invoke(array $context = []): OpenApi + { + $openApi = ($this->decorated)($context); + + return $this->applyProcessors($openApi); + } + + private function applyProcessors(OpenApi $openApi): OpenApi + { + foreach ($this->processors as $processor) { + $openApi = $processor->process($openApi); + } + + return $openApi; + } +} diff --git a/src/OpenApi/Processor/OpenApiProcessorInterface.php b/src/OpenApi/Processor/OpenApiProcessorInterface.php new file mode 100644 index 0000000..5849bfd --- /dev/null +++ b/src/OpenApi/Processor/OpenApiProcessorInterface.php @@ -0,0 +1,21 @@ + Date: Thu, 15 Jan 2026 14:05:23 +0100 Subject: [PATCH 2/6] NGSTACK-1017 add compiler pass for schema processor feature --- .../SchemaProcessorCompilerPass.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/DependencyInjection/CompilerPass/SchemaProcessorCompilerPass.php diff --git a/src/DependencyInjection/CompilerPass/SchemaProcessorCompilerPass.php b/src/DependencyInjection/CompilerPass/SchemaProcessorCompilerPass.php new file mode 100644 index 0000000..9fc9534 --- /dev/null +++ b/src/DependencyInjection/CompilerPass/SchemaProcessorCompilerPass.php @@ -0,0 +1,41 @@ +hasParameter(self::FEATURE_ENABLED_PARAMETER) + || $container->getParameter(self::FEATURE_ENABLED_PARAMETER) === false + ) { + return; + } + + $container + ->setDefinition( + OpenApiFactory::class, + new Definition(OpenApiFactory::class), + ) + ->setArguments([ + new Reference('api_platform.openapi.factory.inner'), + new TaggedIteratorArgument( + tag: 'netgen_api_platform_extras.open_api_processor', + defaultPriorityMethod: 'getPriority', + ), + ]) + ->setDecoratedService('api_platform.openapi.factory', 'api_platform.openapi.factory.inner', -25); + } +} From 40d98e8fdb1ccf92dc752dd0fae23d6458e8481d Mon Sep 17 00:00:00 2001 From: Jakov Knezovic Date: Thu, 15 Jan 2026 14:06:03 +0100 Subject: [PATCH 3/6] NGSTACK-1017 add compiler pass to bundle build and autoconfigure open api processor tag --- src/NetgenApiPlatformExtrasBundle.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/NetgenApiPlatformExtrasBundle.php b/src/NetgenApiPlatformExtrasBundle.php index 3d21b34..47bb08f 100644 --- a/src/NetgenApiPlatformExtrasBundle.php +++ b/src/NetgenApiPlatformExtrasBundle.php @@ -4,6 +4,20 @@ namespace Netgen\ApiPlatformExtras; +use Netgen\ApiPlatformExtras\DependencyInjection\CompilerPass\SchemaProcessorCompilerPass; +use Netgen\ApiPlatformExtras\OpenApi\Processor\OpenApiProcessorInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; -final class NetgenApiPlatformExtrasBundle extends Bundle {} +final class NetgenApiPlatformExtrasBundle extends Bundle +{ + public function build(ContainerBuilder $container): void + { + $container->addCompilerPass( + new SchemaProcessorCompilerPass(), + ); + + $container->registerForAutoconfiguration(OpenApiProcessorInterface::class) + ->addTag('netgen_api_platform_extras.open_api_processor'); + } +} From 8bc59129ec0e7d9549875a4c2e6399b4716bb39f Mon Sep 17 00:00:00 2001 From: Jakov Knezovic Date: Mon, 19 Jan 2026 10:44:59 +0100 Subject: [PATCH 4/6] NGSTACK-1017 remove readonly from class and use fqcn in doc --- src/OpenApi/Factory/OpenApiFactory.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/OpenApi/Factory/OpenApiFactory.php b/src/OpenApi/Factory/OpenApiFactory.php index 48c9d5f..ba52677 100644 --- a/src/OpenApi/Factory/OpenApiFactory.php +++ b/src/OpenApi/Factory/OpenApiFactory.php @@ -6,12 +6,11 @@ use ApiPlatform\OpenApi\Factory\OpenApiFactoryInterface; use ApiPlatform\OpenApi\OpenApi; -use Netgen\ApiPlatformExtras\OpenApi\Processor\OpenApiProcessorInterface; -final readonly class OpenApiFactory implements OpenApiFactoryInterface +final class OpenApiFactory implements OpenApiFactoryInterface { /** - * @param iterable $processors + * @param iterable<\Netgen\ApiPlatformExtras\OpenApi\Processor\OpenApiProcessorInterface> $processors */ public function __construct( private OpenApiFactoryInterface $decorated, From 30375c741790016ace6f1e0a41f33dbe38a1ff58 Mon Sep 17 00:00:00 2001 From: Jakov Knezovic Date: Mon, 19 Jan 2026 11:30:50 +0100 Subject: [PATCH 5/6] NGSTACK-1017 remove default priority method in compiler pass definition and sort processors in factory --- .../SchemaProcessorCompilerPass.php | 5 +---- src/NetgenApiPlatformExtrasBundle.php | 3 ++- src/OpenApi/Factory/OpenApiFactory.php | 22 ++++++++++++++++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/DependencyInjection/CompilerPass/SchemaProcessorCompilerPass.php b/src/DependencyInjection/CompilerPass/SchemaProcessorCompilerPass.php index 9fc9534..8ecb456 100644 --- a/src/DependencyInjection/CompilerPass/SchemaProcessorCompilerPass.php +++ b/src/DependencyInjection/CompilerPass/SchemaProcessorCompilerPass.php @@ -31,10 +31,7 @@ public function process(ContainerBuilder $container): void ) ->setArguments([ new Reference('api_platform.openapi.factory.inner'), - new TaggedIteratorArgument( - tag: 'netgen_api_platform_extras.open_api_processor', - defaultPriorityMethod: 'getPriority', - ), + new TaggedIteratorArgument('netgen_api_platform_extras.open_api_processor'), ]) ->setDecoratedService('api_platform.openapi.factory', 'api_platform.openapi.factory.inner', -25); } diff --git a/src/NetgenApiPlatformExtrasBundle.php b/src/NetgenApiPlatformExtrasBundle.php index 47bb08f..6ae2001 100644 --- a/src/NetgenApiPlatformExtrasBundle.php +++ b/src/NetgenApiPlatformExtrasBundle.php @@ -18,6 +18,7 @@ public function build(ContainerBuilder $container): void ); $container->registerForAutoconfiguration(OpenApiProcessorInterface::class) - ->addTag('netgen_api_platform_extras.open_api_processor'); + ->addTag('netgen_api_platform_extras.open_api_processor') + ->setLazy(true); } } diff --git a/src/OpenApi/Factory/OpenApiFactory.php b/src/OpenApi/Factory/OpenApiFactory.php index ba52677..12fa201 100644 --- a/src/OpenApi/Factory/OpenApiFactory.php +++ b/src/OpenApi/Factory/OpenApiFactory.php @@ -7,6 +7,9 @@ use ApiPlatform\OpenApi\Factory\OpenApiFactoryInterface; use ApiPlatform\OpenApi\OpenApi; +use function iterator_to_array; +use function usort; + final class OpenApiFactory implements OpenApiFactoryInterface { /** @@ -15,7 +18,9 @@ final class OpenApiFactory implements OpenApiFactoryInterface public function __construct( private OpenApiFactoryInterface $decorated, private iterable $processors, - ) {} + ) { + $this->processors = $this->sortProcessors($processors); + } public function __invoke(array $context = []): OpenApi { @@ -32,4 +37,19 @@ private function applyProcessors(OpenApi $openApi): OpenApi return $openApi; } + + /** + * @return iterable<\Netgen\ApiPlatformExtras\OpenApi\Processor\OpenApiProcessorInterface> + */ + private function sortProcessors(iterable $processors): array + { + $processors = iterator_to_array($processors); + + usort( + $processors, + static fn ($a, $b): int => $b->getPriority() <=> $a->getPriority(), + ); + + return $processors; + } } From 309c47314f42d36e6cd06a49e9d440735f609c57 Mon Sep 17 00:00:00 2001 From: Jakov Knezovic Date: Mon, 19 Jan 2026 11:37:15 +0100 Subject: [PATCH 6/6] NGSTACK-1017 fix phpstan issues regarding generic iterable typehint --- src/OpenApi/Factory/OpenApiFactory.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/OpenApi/Factory/OpenApiFactory.php b/src/OpenApi/Factory/OpenApiFactory.php index 12fa201..4583788 100644 --- a/src/OpenApi/Factory/OpenApiFactory.php +++ b/src/OpenApi/Factory/OpenApiFactory.php @@ -39,7 +39,9 @@ private function applyProcessors(OpenApi $openApi): OpenApi } /** - * @return iterable<\Netgen\ApiPlatformExtras\OpenApi\Processor\OpenApiProcessorInterface> + * @param iterable<\Netgen\ApiPlatformExtras\OpenApi\Processor\OpenApiProcessorInterface> $processors + * + * @return \Netgen\ApiPlatformExtras\OpenApi\Processor\OpenApiProcessorInterface[] */ private function sortProcessors(iterable $processors): array { @@ -47,7 +49,7 @@ private function sortProcessors(iterable $processors): array usort( $processors, - static fn ($a, $b): int => $b->getPriority() <=> $a->getPriority(), + static fn ($a, $b): int => $b::getPriority() <=> $a::getPriority(), ); return $processors;