Skip to content

Commit 9d72140

Browse files
Allow to pass processors configuration to swagger-php (#620)
* 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>
1 parent 44bab24 commit 9d72140

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

config/l5-swagger.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,24 @@
102102
],
103103

104104
'scanOptions' => [
105+
/**
106+
* Configuration for default processors. Allows to pass processors configuration to swagger-php.
107+
*
108+
* @link https://zircote.github.io/swagger-php/reference/processors.html
109+
*/
110+
'default_processors_configuration' => [
111+
/** Example */
112+
/**
113+
* 'operationId.hash' => true,
114+
* 'pathFilter' => [
115+
* 'tags' => [
116+
* '/pets/',
117+
* '/store/',
118+
* ],
119+
* ],.
120+
*/
121+
],
122+
105123
/**
106124
* analyser: defaults to \OpenApi\StaticAnalyser .
107125
*

src/Generator.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,14 @@ protected function createOpenApiGenerator(): OpenApiGenerator
202202
{
203203
$generator = new OpenApiGenerator();
204204

205+
// Only from zircote/swagger-php 4
206+
if (! empty($this->scanOptions['default_processors_configuration'])
207+
&& is_array($this->scanOptions['default_processors_configuration'])
208+
&& method_exists($generator, 'setConfig')
209+
) {
210+
$generator->setConfig($this->scanOptions['default_processors_configuration']);
211+
}
212+
205213
// OpenApi spec version - only from zircote/swagger-php 4
206214
if (method_exists($generator, 'setVersion')) {
207215
$generator->setVersion(

src/L5SwaggerServiceProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function register()
5252
$this->app->bind(Generator::class, function ($app) {
5353
$documentation = config('l5-swagger.default');
5454

55+
/** @var GeneratorFactory $factory */
5556
$factory = $app->make(GeneratorFactory::class);
5657

5758
return $factory->make($documentation);

tests/GeneratorTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function canGenerateApiJsonFile(): void
118118
->assertSee('L5 Swagger')
119119
->assertSee('my-default-host.com')
120120
->assertSee('getProjectsList')
121-
->assertSee('getProductsList')
121+
->assertSee('Get list of products')
122122
->assertSee('getClientsList')
123123
->assertStatus(200);
124124

@@ -128,7 +128,7 @@ public function canGenerateApiJsonFile(): void
128128
->assertSee('L5 Swagger')
129129
->assertSee('my-default-host.com')
130130
->assertSee('getProjectsList')
131-
->assertSee('getProductsList')
131+
->assertSee('Get list of products')
132132
->assertSee('getClientsList')
133133
->assertStatus(200);
134134
}
@@ -158,7 +158,7 @@ public function canGenerateWithLegacyExcludedDirectories(): void
158158
->assertSee('L5 Swagger')
159159
->assertSee('my-default-host.com')
160160
->assertSee('getProjectsList')
161-
->assertSee('getProductsList')
161+
->assertSee('Get list of products')
162162
->assertDontSee('getClientsList')
163163
->assertStatus(200);
164164
}
@@ -178,6 +178,9 @@ public function canGenerateWithScanOptions(): void
178178
$cfg['scanOptions']['processors'] = [
179179
new CleanUnmerged,
180180
];
181+
$cfg['scanOptions']['default_processors_configuration'] = [
182+
'operationId' => ['hash' => false],
183+
];
181184

182185
config(['l5-swagger' => [
183186
'default' => 'default',
@@ -199,7 +202,8 @@ public function canGenerateWithScanOptions(): void
199202
->assertSee('3.1.0')
200203
->assertSee('my-default-host.com')
201204
->assertSee('getProjectsList')
202-
->assertSee('getProductsList')
205+
->assertSee('operationId')
206+
->assertSee("POST::/products::Tests\\\storage\\\annotations\\\OpenApi\\\Products\\\L5SwaggerAnnotationsExampleProducts::getProductsList")
203207
->assertDontSee('getClientsList')
204208
->assertStatus(200);
205209
}

tests/storage/annotations/OpenApi/Products/L5SwaggerAnnotationsExampleProducts.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class L5SwaggerAnnotationsExampleProducts
77
/**
88
* @OA\Post(
99
* path="/products",
10-
* operationId="getProductsList",
1110
* tags={"Products"},
1211
* summary="Get list of products",
1312
* description="Returns list of products",

0 commit comments

Comments
 (0)