From 9d1d5e88d54b99cd5854900d5cbb975438b59e6d Mon Sep 17 00:00:00 2001 From: DerManoMann Date: Thu, 11 Jun 2026 12:59:28 +1200 Subject: [PATCH 1/3] Add support for positioning custom processors --- config/l5-swagger.php | 10 ++++++++-- src/Generator.php | 31 ++++++++++++++++++++++--------- tests/Unit/GeneratorTest.php | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 11 deletions(-) diff --git a/config/l5-swagger.php b/config/l5-swagger.php index a3ce546..cba3551 100644 --- a/config/l5-swagger.php +++ b/config/l5-swagger.php @@ -135,13 +135,19 @@ 'analysis' => null, /** - * Custom query path processors classes. + * Custom processors. + * + * Each entry can be: + * - A class name or instance (inserted after BuildPaths by default) + * - An array with 'class' and 'after' keys for precise positioning: + * ['class' => MyProcessor::class, 'after' => SomeProcessor::class] * * @link https://github.com/zircote/swagger-php/tree/master/Examples/processors/schema-query-parameter * @see \OpenApi\scan */ 'processors' => [ - // new \App\SwaggerProcessors\SchemaQueryParameter(), + // \App\SwaggerProcessors\SchemaQueryParameter::class, + // ['class' => \App\SwaggerProcessors\Custom::class, 'after' => \OpenApi\Processors\AugmentSchemas::class], ], /** diff --git a/src/Generator.php b/src/Generator.php index 59c2db3..0eb5521 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -215,23 +215,36 @@ protected function createOpenApiGenerator(): OpenApiGenerator */ protected function setProcessors(OpenApiGenerator $generator): void { - $processorClasses = Arr::get($this->scanOptions, self::SCAN_OPTION_PROCESSORS, []); - $newPipeLine = []; + $processorConfigs = Arr::get($this->scanOptions, self::SCAN_OPTION_PROCESSORS, []); + if (empty($processorConfigs)) { + return; + } + + $normalizedConfigs = []; + foreach ($processorConfigs as $config) { + if (is_array($config)) { + $normalizedConfigs[] = $config; + } else { + $normalizedConfigs[] = ['class' => $config, 'after' => \OpenApi\Processors\BuildPaths::class]; + } + } + + $newPipeLine = []; $generator->getProcessorPipeline()->walk( - function (callable $pipe) use ($processorClasses, &$newPipeLine) { + function (callable $pipe) use ($normalizedConfigs, &$newPipeLine) { $newPipeLine[] = $pipe; - if ($pipe instanceof \OpenApi\Processors\BuildPaths) { - foreach ($processorClasses as $customProcessor) { - $newPipeLine[] = new $customProcessor(); + foreach ($normalizedConfigs as $entry) { + $after = $entry['after']; + if ($pipe instanceof $after) { + $processor = $entry['class']; + $newPipeLine[] = is_string($processor) ? new $processor() : $processor; } } } ); - if (! empty($newPipeLine)) { - $generator->setProcessorPipeline(new Pipeline($newPipeLine)); - } + $generator->setProcessorPipeline(new Pipeline($newPipeLine)); } /** diff --git a/tests/Unit/GeneratorTest.php b/tests/Unit/GeneratorTest.php index 7ea0c83..58eae4e 100644 --- a/tests/Unit/GeneratorTest.php +++ b/tests/Unit/GeneratorTest.php @@ -12,6 +12,7 @@ use OpenApi\Analysers\ReflectionAnalyser; use OpenApi\OpenApiException; use OpenApi\Processors\AugmentParameters; +use OpenApi\Processors\AugmentSchemas; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\TestDox; use Symfony\Component\Yaml\Parser; @@ -225,6 +226,38 @@ public function testCanGenerateWithScanOptions(): void ->assertStatus(200); } + /** + * @throws L5SwaggerException + */ + public function testCanGenerateWithProcessorPositioning(): void + { + $cfg = config('l5-swagger.documentations.default'); + + $cfg['scanOptions'] = [ + 'processors' => [ + new AugmentParameters(), + ['class' => AugmentSchemas::class, 'after' => AugmentParameters::class], + ], + 'default_processors_configuration' => ['operationId' => ['hash' => false]], + ]; + + config(['l5-swagger' => [ + 'default' => 'default', + 'documentations' => ['default' => $cfg], + 'defaults' => config('l5-swagger.defaults'), + ]]); + + $this->setAnnotationsPath(); + + $this->generator->generateDocs(); + + $this->assertFileExists($this->jsonDocsFile()); + + $this->get(route('l5-swagger.default.docs')) + ->assertSee('L5 Swagger') + ->assertStatus(200); + } + /** * @throws L5SwaggerException */ From 8d19d57b011cf3b91722c7ddd1c071d0ce7697bd Mon Sep 17 00:00:00 2001 From: DerManoMann Date: Fri, 12 Jun 2026 11:44:08 +1200 Subject: [PATCH 2/3] CS --- src/Generator.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Generator.php b/src/Generator.php index 0eb5521..b65afc1 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -223,11 +223,9 @@ protected function setProcessors(OpenApiGenerator $generator): void $normalizedConfigs = []; foreach ($processorConfigs as $config) { - if (is_array($config)) { - $normalizedConfigs[] = $config; - } else { - $normalizedConfigs[] = ['class' => $config, 'after' => \OpenApi\Processors\BuildPaths::class]; - } + $normalizedConfigs[] = is_array($config) + ? $config + : ['class' => $config, 'after' => \OpenApi\Processors\BuildPaths::class]; } $newPipeLine = []; From 71de0a1c48281409249d34a0df1ec32994b09033 Mon Sep 17 00:00:00 2001 From: Darius Matulionis Date: Fri, 12 Jun 2026 12:06:22 +0300 Subject: [PATCH 3/3] Update GeneratorTest.php --- tests/Unit/GeneratorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/GeneratorTest.php b/tests/Unit/GeneratorTest.php index 16c795e..e29acde 100644 --- a/tests/Unit/GeneratorTest.php +++ b/tests/Unit/GeneratorTest.php @@ -260,7 +260,7 @@ public function testCanGenerateWithProcessorPositioning(): void ->assertSee('L5 Swagger') ->assertStatus(200); } - + /** * @throws L5SwaggerException */