Skip to content

Commit

Permalink
Allow to pass processors configuration to swagger-php (#620)
Browse files Browse the repository at this point in the history
* Allow to pass processors configuration to swagger-php

* Apply fixes from StyleCI

* add test

* add test

* cs

* cs

* cs

* update tests

* update tests

---------

Co-authored-by: StyleCI Bot <bot@styleci.io>
  • Loading branch information
DarkaOnLine and StyleCIBot authored Aug 29, 2024
1 parent 44bab24 commit 9d72140
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
18 changes: 18 additions & 0 deletions config/l5-swagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
*
Expand Down
8 changes: 8 additions & 0 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/L5SwaggerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 8 additions & 4 deletions tests/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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',
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class L5SwaggerAnnotationsExampleProducts
/**
* @OA\Post(
* path="/products",
* operationId="getProductsList",
* tags={"Products"},
* summary="Get list of products",
* description="Returns list of products",
Expand Down

0 comments on commit 9d72140

Please sign in to comment.