Skip to content

Commit

Permalink
Make @OA\Server annotation be compatible with L5_SWAGGER_BASE_PATH en…
Browse files Browse the repository at this point in the history
…vironment variable (#239)
  • Loading branch information
ymhuang0808 authored and DarkaOnLine committed Nov 8, 2019
1 parent e5d4441 commit df9e72d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Generator.php
Expand Up @@ -139,9 +139,11 @@ protected function populateServers()
{
if (config('l5-swagger.paths.base') !== null) {
if ($this->isOpenApi()) {
$this->swagger->servers = [
new \OpenApi\Annotations\Server(['url' => config('l5-swagger.paths.base')]),
];
if (! is_array($this->swagger->servers)) {
$this->swagger->servers = [];
}

$this->swagger->servers[] = new \OpenApi\Annotations\Server(['url' => config('l5-swagger.paths.base')]);
}

if (! $this->isOpenApi()) {
Expand Down
2 changes: 2 additions & 0 deletions tests/GeneratorTest.php
Expand Up @@ -91,11 +91,13 @@ public function canGenerateApiJsonFileWithChangedBaseServer()

$this->get(route('l5-swagger.docs'))
->assertSee('https://test-server.url')
->assertSee('https://projects.dev/api/v1')
->assertDontSee('basePath')
->assertStatus(200);

$this->get(route('l5-swagger.docs', ['jsonFile' => config('l5-swagger.paths.docs_yaml')]))
->assertSee('https://test-server.url')
->assertSee('https://projects.dev/api/v1')
->assertDontSee('basePath')
->assertStatus(200);
}
Expand Down

0 comments on commit df9e72d

Please sign in to comment.