Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to pass processors configuration to swagger-php #620

Merged
merged 10 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading