Skip to content

Commit

Permalink
Merge branch 'master' into use-attributes-in-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkaOnLine committed Aug 29, 2024
2 parents 396d9d2 + 9d72140 commit 80c3f2f
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 @@ -135,7 +135,7 @@ public function testCanGenerateApiJsonFile(): void
->assertSee('L5 Swagger')
->assertSee('my-default-host.com')
->assertSee('getProjectsList')
->assertSee('getProductsList')
->assertSee('Get list of products')
->assertSee('getClientsList')
->assertStatus(200);

Expand All @@ -145,7 +145,7 @@ public function testCanGenerateApiJsonFile(): 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 @@ -177,7 +177,7 @@ public function testCanGenerateWithLegacyExcludedDirectories(): void
->assertSee('L5 Swagger')
->assertSee('my-default-host.com')
->assertSee('getProjectsList')
->assertSee('getProductsList')
->assertSee('Get list of products')
->assertDontSee('getClientsList')
->assertStatus(200);
}
Expand All @@ -199,6 +199,9 @@ public function testCanGenerateWithScanOptions(): void
$cfg['scanOptions']['processors'] = [
new CleanUnmerged,
];
$cfg['scanOptions']['default_processors_configuration'] = [
'operationId' => ['hash' => false],
];

config(['l5-swagger' => [
'default' => 'default',
Expand All @@ -220,7 +223,8 @@ public function testCanGenerateWithScanOptions(): 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 80c3f2f

Please sign in to comment.