diff --git a/config/l5-swagger.php b/config/l5-swagger.php index 38bc42a..3d18860 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..8282fed 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -202,6 +202,14 @@ 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); diff --git a/tests/GeneratorTest.php b/tests/GeneratorTest.php index 3b4bcce..c60129b 100644 --- a/tests/GeneratorTest.php +++ b/tests/GeneratorTest.php @@ -118,7 +118,7 @@ public function canGenerateApiJsonFile(): void ->assertSee('L5 Swagger') ->assertSee('my-default-host.com') ->assertSee('getProjectsList') - ->assertSee('getProductsList') + ->assertSee('Get list of products') ->assertSee('getClientsList') ->assertStatus(200); @@ -128,7 +128,7 @@ public function canGenerateApiJsonFile(): void ->assertSee('L5 Swagger') ->assertSee('my-default-host.com') ->assertSee('getProjectsList') - ->assertSee('getProductsList') + ->assertSee('Get list of products') ->assertSee('getClientsList') ->assertStatus(200); } @@ -158,7 +158,7 @@ public function canGenerateWithLegacyExcludedDirectories(): void ->assertSee('L5 Swagger') ->assertSee('my-default-host.com') ->assertSee('getProjectsList') - ->assertSee('getProductsList') + ->assertSee('Get list of products') ->assertDontSee('getClientsList') ->assertStatus(200); } @@ -178,6 +178,9 @@ public function canGenerateWithScanOptions(): void $cfg['scanOptions']['processors'] = [ new CleanUnmerged, ]; + $cfg['scanOptions']['default_processors_configuration'] = [ + 'operationId' => ['hash' => false], + ]; config(['l5-swagger' => [ 'default' => 'default', @@ -199,7 +202,8 @@ public function canGenerateWithScanOptions(): void ->assertSee('3.1.0') ->assertSee('my-default-host.com') ->assertSee('getProjectsList') - ->assertSee('getProductsList') + ->assertSee('operationId') + ->assertSee("POST::/products::Tests\\\storage\\\annotations\\\OpenApi\\\Products\\\L5SwaggerAnnotationsExampleProducts::getProductsList") ->assertDontSee('getClientsList') ->assertStatus(200); } diff --git a/tests/storage/annotations/OpenApi/Products/L5SwaggerAnnotationsExampleProducts.php b/tests/storage/annotations/OpenApi/Products/L5SwaggerAnnotationsExampleProducts.php index 7111679..3da43f7 100644 --- a/tests/storage/annotations/OpenApi/Products/L5SwaggerAnnotationsExampleProducts.php +++ b/tests/storage/annotations/OpenApi/Products/L5SwaggerAnnotationsExampleProducts.php @@ -7,7 +7,6 @@ class L5SwaggerAnnotationsExampleProducts /** * @OA\Post( * path="/products", - * operationId="getProductsList", * tags={"Products"}, * summary="Get list of products", * description="Returns list of products",