Skip to content

Commit

Permalink
Merge pull request #24 from nextapps-be/feature/add-stylesheet
Browse files Browse the repository at this point in the history
Config option to add css to customize swagger-ui
  • Loading branch information
gdebrauwer authored Oct 30, 2023
2 parents 8b9c603 + 33cf215 commit 171adce
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config/swagger-ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
'client_id' => env('SWAGGER_UI_OAUTH_CLIENT_ID'),
'client_secret' => env('SWAGGER_UI_OAUTH_CLIENT_SECRET'),
],

/*
* Path to a custom stylesheet file if you want to customize the look and feel of swagger-ui.
* The content of the file will be read and added into a style-tag on the swagger-ui page.
*/
'stylesheet' => null,
],
],
];
4 changes: 4 additions & 0 deletions resources/views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
background: #fafafa;
}
</style>

@if (! empty($data['stylesheet']))
<style>{{ file_get_contents($data['stylesheet']) }}</style>
@endif
</head>
<body>
<div id="swagger-ui"></div>
Expand Down
15 changes: 15 additions & 0 deletions tests/SwaggerUiRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,19 @@ public function it_applies_middleware_from_config()

$this->assertRouteUsesMiddleware('swagger-with-versions.index', ['web']);
}

/** @test */
public function it_includes_content_of_custom_stylesheet()
{
file_put_contents(
$path = resource_path('custom-swagger-ui-styling.css'),
$content = '.foo .bar { background-color: red; }'
);

config()->set('swagger-ui.files.0.stylesheet', $path);

$this->get('swagger')
->assertStatus(200)
->assertSee("<style>{$content}</style>", false);
}
}

0 comments on commit 171adce

Please sign in to comment.