From 84639e8a2a5c526422bffaaa5840888589ad92a7 Mon Sep 17 00:00:00 2001 From: Darius Matulionis Date: Wed, 28 Aug 2024 15:23:05 +0300 Subject: [PATCH] Allow to pass processors configuration to swagger-php --- config/l5-swagger.php | 18 ++++++++++++++++++ src/Generator.php | 9 +++++++++ src/L5SwaggerServiceProvider.php | 1 + 3 files changed, 28 insertions(+) diff --git a/config/l5-swagger.php b/config/l5-swagger.php index 38bc42a..4fe5554 100644 --- a/config/l5-swagger.php +++ b/config/l5-swagger.php @@ -102,6 +102,24 @@ ], 'scanOptions' => [ + /** + * Configuration for default processors. Allows to pass processors configuration to swagger-php + * + * @link https://zircote.github.io/swagger-php/reference/processors.html + */ + 'default_processors_configuration' => [ + /** Example */ + /** + 'operationId.hash' => true, + 'pathFilter' => [ + 'tags' => [ + '/pets/', + '/store/', + ], + ], + */ + ], + /** * analyser: defaults to \OpenApi\StaticAnalyser . * diff --git a/src/Generator.php b/src/Generator.php index 0e0dacc..e626592 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -202,6 +202,15 @@ protected function createOpenApiGenerator(): OpenApiGenerator { $generator = new OpenApiGenerator(); + // Only from zircote/swagger-php 4 + if ( + !empty($this->scanOptions['default_processors_configuration']) + && is_array($this->scanOptions['default_processors_configuration']) + && method_exists($generator, 'setConfig') + ) { + $generator->setConfig($this->scanOptions['default_processors_configuration']); + } + // OpenApi spec version - only from zircote/swagger-php 4 if (method_exists($generator, 'setVersion')) { $generator->setVersion( diff --git a/src/L5SwaggerServiceProvider.php b/src/L5SwaggerServiceProvider.php index 82fb70d..2c352f3 100644 --- a/src/L5SwaggerServiceProvider.php +++ b/src/L5SwaggerServiceProvider.php @@ -52,6 +52,7 @@ public function register() $this->app->bind(Generator::class, function ($app) { $documentation = config('l5-swagger.default'); + /** @var GeneratorFactory $factory */ $factory = $app->make(GeneratorFactory::class); return $factory->make($documentation);