From 9f779c4c292ad9b11bbf4ee99eedcd322f807652 Mon Sep 17 00:00:00 2001 From: Rico Nijeboer Date: Mon, 30 Aug 2021 21:22:22 +0200 Subject: [PATCH] ![redoc-only](https://img.shields.io/badge/Redoc%20Only-red.svg) You can now add a logo to your redoc config --- CHANGELOG.md | 7 +++++++ README.md | 20 ++++++++++++++++++++ config/swagger.php | 17 +++++++++++++++++ src/Actions/BuildOpenApiConfigAction.php | 14 +++++++++++++- 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b627dfb..f522cbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes will be documented here. +## v2.4.2 - 30-08-2021 + +**Changes** + +- ![redoc-only](https://img.shields.io/badge/Redoc%20Only-red.svg) You can now add a logo to your redoc config + - [Documentation](https://github.com/RicoNijeboer/laravel-to-swagger#adding-a-logo) + ## v2.4.1 - 30-08-2021 **Changes** diff --git a/README.md b/README.md index 915373c..cb45c6d 100644 --- a/README.md +++ b/README.md @@ -297,6 +297,26 @@ return [ ]; ``` +### Adding a logo +![redoc-only](https://img.shields.io/badge/Redoc%20Only-red.svg) + +You can add a logo to the sidebar in your Redoc visualization by adding a full-url to the `swagger.info.logo.url`. + +> The logo is only displayed when you use the Redoc documentation route. + +```php +return [ + //... + 'info' => [ + //... + 'logo' => [ + 'url' => 'https://picsum.photos/300/200', + ], + ], + //... +]; +``` + ## Testing ``` diff --git a/config/swagger.php b/config/swagger.php index 57c5d07..3a3a173 100644 --- a/config/swagger.php +++ b/config/swagger.php @@ -22,6 +22,23 @@ 'title' => 'Laravel to Swagger', 'description' => null, 'version' => '0.0.1', + + 'logo' => [ + /* + * The URL pointing to the spec logo. + * MUST be in the format of a URL. + * It SHOULD be an absolute URL so your API definition is usable from any location + */ + 'url' => null, + /* + * Background color to be used. MUST be RGB color in [hexadecimal format] + */ + 'background-color' => '#ffffff', + /* + * Text to use for alt tag on the logo. Defaults to 'logo' if nothing is provided. + */ + 'alt-text' => null, + ], ], /* diff --git a/src/Actions/BuildOpenApiConfigAction.php b/src/Actions/BuildOpenApiConfigAction.php index 85d10ed..b95a83a 100644 --- a/src/Actions/BuildOpenApiConfigAction.php +++ b/src/Actions/BuildOpenApiConfigAction.php @@ -60,11 +60,23 @@ public function build(): array */ protected function getInfo(): array { - return array_filter([ + $info = array_filter([ 'title' => config('swagger.info.title'), 'description' => config('swagger.info.description'), 'version' => config('swagger.info.version'), ]); + + $logo = array_filter([ + 'url' => config('swagger.info.logo.url'), + 'backgroundColor' => config('swagger.info.logo.background-color'), + 'altText' => config('swagger.info.logo.alt-text'), + ]); + + if (\array_key_exists('url', $logo)) { + $info['x-logo'] = $logo; + } + + return $info; } /**