Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
…can now add a logo to your redoc config
  • Loading branch information
Rico Nijeboer committed Aug 30, 2021
1 parent 9ab9d32 commit 9f779c4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down
17 changes: 17 additions & 0 deletions config/swagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
],

/*
Expand Down
14 changes: 13 additions & 1 deletion src/Actions/BuildOpenApiConfigAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 9f779c4

Please sign in to comment.