Skip to content

Commit d08c3ed

Browse files
committed
Add Swagger UI
1 parent 65971e8 commit d08c3ed

File tree

7 files changed

+69
-0
lines changed

7 files changed

+69
-0
lines changed

lib/OpenQA/WebAPI.pm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ sub startup ($self) {
2929
url => $self->home->rel_file('public/openapi.yaml'),
3030
},
3131
);
32+
push @{$self->app->static()->paths()}, $self->home->rel_file('swagger');
33+
push @{$self->app->renderer()->paths()}, $self->home->rel_file('swagger');
3234

3335
# Provide help to users early to prevent failing later on misconfigurations
3436
# note: Loading plugins for the current configuration so the help of commands provided by plugins is
@@ -208,6 +210,7 @@ sub startup ($self) {
208210
$r->get('/dashboard_build_results' => [format => ['json', 'html']])->name('dashboard_build_results')
209211
->to('main#dashboard_build_results', format => undef);
210212
$r->get('/api_help' => sub ($c) { $c->render('admin/api_help') })->name('api_help');
213+
$r->get('/swagger' => sub ($c) { $c->render('swagger') })->name('swagger');
211214

212215
# Default route
213216
$r->get('/' => sub ($c) { $c->render('main/index') })->name('index');

public/swagger/index.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
html {
2+
box-sizing: border-box;
3+
overflow: -moz-scrollbars-vertical;
4+
overflow-y: scroll;
5+
}
6+
7+
*,
8+
*:before,
9+
*:after {
10+
box-sizing: inherit;
11+
}
12+
13+
body {
14+
margin: 0;
15+
background: #fafafa;
16+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
window.onload = function() {
2+
const defaultDefinitionUrl = "http://localhost:9526/openapi.yaml";
3+
const definitionURL = defaultDefinitionUrl;
4+
5+
//<editor-fold desc="Changeable Configuration Block">
6+
window.ui = SwaggerUIBundle({
7+
url: definitionURL,
8+
"dom_id": "#swagger-ui",
9+
deepLinking: true,
10+
presets: [
11+
SwaggerUIBundle.presets.apis,
12+
SwaggerUIStandalonePreset
13+
],
14+
plugins: [
15+
SwaggerUIBundle.plugins.DownloadUrl
16+
],
17+
layout: "StandaloneLayout",
18+
queryConfigEnabled: true,
19+
validatorUrl: "https://validator.swagger.io/validator",
20+
})
21+
//</editor-fold>
22+
23+
};

public/swagger/swagger-ui-bundle.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/swagger/swagger-ui-standalone-preset.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/swagger/swagger-ui.css

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/webapi/swagger.html.ep

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!-- HTML for static distribution bundle build -->
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>Swagger UI</title>
7+
<link rel="stylesheet" type="text/css" href="/swagger/swagger-ui.css" />
8+
<link rel="stylesheet" type="text/css" href="index.css" />
9+
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
10+
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
11+
</head>
12+
13+
<body>
14+
<div id="swagger-ui"></div>
15+
<script src="/swagger/swagger-ui-bundle.js" charset="UTF-8"> </script>
16+
<script src="/swagger/swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
17+
<script src="/swagger/swagger-initializer.js" charset="UTF-8"> </script>
18+
</body>
19+
</html>
20+

0 commit comments

Comments
 (0)