Skip to content

Commit

Permalink
feat: custom html title
Browse files Browse the repository at this point in the history
  • Loading branch information
hms5232 committed Aug 15, 2024
1 parent 5f5aad4 commit 03d61e2
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
12 changes: 12 additions & 0 deletions config/swagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
*/
'path' => env('LARAVEL_SWAGGER_UI_PATH', 'swagger'),

/*
* Specify the html title of Swagger UI.
* If not set (null), Default is: <APP_NAME> - SwaggerUI
*/
'title' => env('LARAVEL_SWAGGER_UI_TITLE'),

/*
* Specify which Swagger UI version should be used.
* Leave it null if you want to use default version of laravel-swagger.
Expand All @@ -115,6 +121,12 @@
*/
'path' => env('LARAVEL_SWAGGER_EDITOR_PATH', 'swagger-editor'),

/*
* Specify the html title of Swagger Editor.
* If not set (null), Default is: <APP_NAME> - SwaggerEditor
*/
'title' => env('LARAVEL_SWAGGER_EDITOR_TITLE'),

/*
* Specify which Swagger Editor version should be used.
* Leave it null if you want to use default version of laravel-swagger.
Expand Down
3 changes: 2 additions & 1 deletion resources/views/editor.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@

@php
$ver = config('swagger.editor.ver') ?? '4.5.0';
$title = config('swagger.editor.title', config('app.name') . ' - Swagger Editor');
@endphp

<!DOCTYPE html>
<!-- HTML for static distribution bundle build -->
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ config('app.name') }} - Swagger Editor</title>
<title>{{ $title }}</title>
<style>
* {
box-sizing: border-box;
Expand Down
3 changes: 2 additions & 1 deletion resources/views/ui.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

@php
$ver = config('swagger.ui.ver') ?? '4.5.0';
$title = config('swagger.ui.title', config('app.name') . ' - SwaggerUI');
@endphp

<!DOCTYPE html>
Expand All @@ -20,7 +21,7 @@
name="description"
content="SwaggerUI"
/>
<title>{{ config('app.name') }} - SwaggerUI</title>
<title>{{ $title }}</title>
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist{{ '@' . $ver }}/swagger-ui.css" />
</head>
<body>
Expand Down
22 changes: 22 additions & 0 deletions tests/SwaggerEditorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ protected function swaggerCustomFileDomain($app)
$app['config']->set('swagger.file_url', 'https://laravel-swagger.hhming.moe');
}

/**
* Define environment setup for enabling Laravel Swagger,
* custom html title.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected function swaggerCustomTitle($app)
{
$this->enableLS($app);
$app['config']->set('swagger.editor.title', 'Custom Swagger Editor');
}

#[Test]
#[DefineEnvironment('disableLS')]
public function testDisable()
Expand Down Expand Up @@ -136,4 +149,13 @@ public function testCustomFileDomain()
$res->assertDontSee('http://localhost/swagger-doc/openapi.yaml');
$res->assertSee('https://laravel-swagger.hhming.moe/swagger-doc/openapi.yaml');
}

#[Test]
#[DefineEnvironment('swaggerCustomTitle')]
public function testCustomTitle()
{
$res = $this->get('/swagger-editor');
$res->assertDontSee(' - Swagger Editor');
$res->assertSee('Custom Swagger Editor');
}
}
22 changes: 22 additions & 0 deletions tests/SwaggerUiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ protected function swaggerCustomFileDomain($app)
$app['config']->set('swagger.file_url', 'https://laravel-swagger.hhming.moe');
}

/**
* Define environment setup for enabling Laravel Swagger,
* custom html title.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected function swaggerCustomTitle($app)
{
$this->enableLS($app);
$app['config']->set('swagger.ui.title', 'My Swagger UI');
}

#[Test]
#[DefineEnvironment('disableLS')]
public function testDisable()
Expand Down Expand Up @@ -133,4 +146,13 @@ public function testCustomFileDomain()
$res->assertDontSee('http://localhost/swagger-doc/openapi.yaml');
$res->assertSee('https://laravel-swagger.hhming.moe/swagger-doc/openapi.yaml');
}

#[Test]
#[DefineEnvironment('swaggerCustomTitle')]
public function testCustomTitle()
{
$res = $this->get('/swagger');
$res->assertDontSee(' - SwaggerUI'); // Default title
$res->assertSee('My Swagger UI');
}
}

0 comments on commit 03d61e2

Please sign in to comment.