Skip to content

Commit

Permalink
Stylesheet per api file / path
Browse files Browse the repository at this point in the history
  • Loading branch information
gdebrauwer committed Oct 30, 2023
1 parent 4263c32 commit 33cf215
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
12 changes: 6 additions & 6 deletions config/swagger-ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +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,
],
],

/**
* 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,
];
6 changes: 2 additions & 4 deletions resources/views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
}
</style>

@if (config('swagger-ui.stylesheet'))
<style>
{{ file_get_contents(config('swagger-ui.stylesheet')) }}
</style>
@if (! empty($data['stylesheet']))
<style>{{ file_get_contents($data['stylesheet']) }}</style>
@endif
</head>
<body>
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 33cf215

Please sign in to comment.