Skip to content

Commit

Permalink
Test for openApi server spec
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkaOnLine committed Jun 11, 2018
1 parent 0e3d434 commit b079614
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use File;
use Config;
use Swagger\Annotations\Server;

class Generator
{
Expand Down Expand Up @@ -43,9 +42,10 @@ protected static function generateServers($swagger)
{
if (config('l5-swagger.paths.base') !== null) {
$isVersion3 = version_compare(config('l5-swagger.swagger_version'), '3.0', '>=');

if ($isVersion3) {
$swagger->servers = [
new Server(['url' => config('l5-swagger.paths.base')]),
new \Swagger\Annotations\Server(['url' => config('l5-swagger.paths.base')]),
];
}

Expand Down
24 changes: 24 additions & 0 deletions tests/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,30 @@ public function canGenerateApiJsonFileWithChangedBasePath()
->isOk();
}

/** @test */
public function canGenerateApiJsonFileWithChangedBaseServer()
{
if (! $this->isOpenApi()) {
$this->markTestSkipped('only for openApi 3.0');
}

$this->setAnnotationsPath();

$cfg = config('l5-swagger');
$cfg['paths']['base'] = 'https://test-server.url';
$cfg['swagger_version'] = '3.0';
config(['l5-swagger' => $cfg]);

tap(new Generator)->generateDocs();

$this->assertTrue(file_exists($this->jsonDocsFile()));

$this->get(route('l5-swagger.docs'))
->assertSee('https://test-server.url')
->assertDontSee('basePath')
->isOk();
}

/** @test */
public function canSetProxy()
{
Expand Down

0 comments on commit b079614

Please sign in to comment.