Skip to content

Commit

Permalink
update swagger ui (#1711)
Browse files Browse the repository at this point in the history
  • Loading branch information
lovromazgon authored Jul 18, 2024
1 parent 203aeb7 commit fab3ab9
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 69 deletions.
6 changes: 3 additions & 3 deletions pkg/web/openapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

This directory contains an abbreviated copy of the following repository:

* `swagger-ui` - https://github.com/swagger-api/swagger-ui 91858cc811d3cddb45ef604365e2c88cd96e4ca0 (LICENSE, dist/)
* `swagger-ui` - https://github.com/swagger-api/swagger-ui 8e6824cb452ae4b268f45f5203575194217c6653 (LICENSE, dist/)

The `swagger-ui` directory contains HTML, Javascript, and CSS assets that dynamically generate Swagger documentation
from a Swagger-compliant API definition in [api.swagger.json](./swagger-ui/api/v1/api.swagger.json) file.
That file is auto-generated by running `make proto` in the root of this repository. The static assets are copied
from [this dist folder](https://github.com/swagger-api/swagger-ui/tree/master/dist) of the swagger-ui project. After
copying, [`index.html`](./swagger-ui/index.html) is edited to load the swagger file from the local server instead of the
default petstore.
copying, [`swagger-initializer.js`](./swagger-ui/swagger-initializer.js) is edited to load the swagger file from the
local server instead of the default petstore. All `*.js.map` files are removed to decrease the size of the binary.

See the [LICENSE](./swagger-ui/LICENSE) file for applicable license terms.
16 changes: 16 additions & 0 deletions pkg/web/openapi/swagger-ui/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
html {
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}

*,
*:before,
*:after {
box-sizing: inherit;
}

body {
margin: 0;
background: #fafafa;
}
45 changes: 2 additions & 43 deletions pkg/web/openapi/swagger-ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,15 @@
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" />
<link rel="stylesheet" type="text/css" href="index.css" />
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
<style>
html
{
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}

*,
*:before,
*:after
{
box-sizing: inherit;
}

body
{
margin:0;
background: #fafafa;
}
</style>
</head>

<body>
<div id="swagger-ui"></div>

<script src="./swagger-ui-bundle.js" charset="UTF-8"> </script>
<script src="./swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
<script>
window.onload = function() {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "./api/v1/api.swagger.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset.slice(1) // remove top bar
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
});
// End Swagger UI call region

window.ui = ui;
};
</script>
<script src="./swagger-initializer.js" charset="UTF-8"> </script>
</body>
</html>
16 changes: 10 additions & 6 deletions pkg/web/openapi/swagger-ui/oauth2-redirect.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
var isValid, qp, arr;

if (/code|token|error/.test(window.location.hash)) {
qp = window.location.hash.substring(1);
qp = window.location.hash.substring(1).replace('?', '&');
} else {
qp = location.search.substring(1);
}
Expand All @@ -38,7 +38,7 @@
authId: oauth2.auth.name,
source: "auth",
level: "warning",
message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
message: "Authorization may be unsafe, passed state was changed in server. The passed state wasn't returned from auth server."
});
}

Expand All @@ -58,7 +58,7 @@
authId: oauth2.auth.name,
source: "auth",
level: "error",
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server"
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server."
});
}
} else {
Expand All @@ -67,9 +67,13 @@
window.close();
}

window.addEventListener('DOMContentLoaded', function () {
run();
});
if (document.readyState !== 'loading') {
run();
} else {
document.addEventListener('DOMContentLoaded', function () {
run();
});
}
</script>
</body>
</html>
18 changes: 18 additions & 0 deletions pkg/web/openapi/swagger-ui/swagger-initializer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
window.onload = function() {
//<editor-fold desc="Changeable Configuration Block">

// the following lines will be replaced by docker/configurator, when it runs in a docker-container
window.ui = SwaggerUIBundle({
url: "./api/v1/api.swagger.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
});

//</editor-fold>
};
3 changes: 1 addition & 2 deletions pkg/web/openapi/swagger-ui/swagger-ui-bundle.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion pkg/web/openapi/swagger-ui/swagger-ui-bundle.js.map

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/web/openapi/swagger-ui/swagger-ui-es-bundle-core.js

Large diffs are not rendered by default.

This file was deleted.

3 changes: 1 addition & 2 deletions pkg/web/openapi/swagger-ui/swagger-ui-es-bundle.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion pkg/web/openapi/swagger-ui/swagger-ui-es-bundle.js.map

This file was deleted.

3 changes: 1 addition & 2 deletions pkg/web/openapi/swagger-ui/swagger-ui-standalone-preset.js

Large diffs are not rendered by default.

This file was deleted.

3 changes: 1 addition & 2 deletions pkg/web/openapi/swagger-ui/swagger-ui.css

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion pkg/web/openapi/swagger-ui/swagger-ui.css.map

This file was deleted.

3 changes: 1 addition & 2 deletions pkg/web/openapi/swagger-ui/swagger-ui.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion pkg/web/openapi/swagger-ui/swagger-ui.js.map

This file was deleted.

0 comments on commit fab3ab9

Please sign in to comment.