Skip to content

Commit

Permalink
Merge branch 'alex/swagger-ui3' of https://github.com/Alexei-Kornienk…
Browse files Browse the repository at this point in the history
…o/aiohttp-swagger into Alexei-Kornienko-alex/swagger-ui3
  • Loading branch information
Goran Pavlovic committed Nov 28, 2019
2 parents a749d4b + dacb786 commit 066d800
Show file tree
Hide file tree
Showing 14 changed files with 263 additions and 3 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include LICENSE CHANGELOG README.md requirements.txt requirements-performance.txt
recursive-include aiohttp_swagger/templates *
recursive-include aiohttp_swagger/swagger_ui *
recursive-include aiohttp_swagger/swagger_ui3 *

recursive-exclude * __pycache__
recursive-exclude * *.pyc
Expand Down
9 changes: 6 additions & 3 deletions aiohttp_swagger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ async def _swagger_def(request):
return web.json_response(text=request.app["SWAGGER_DEF_CONTENT"])


STATIC_PATH = abspath(join(dirname(__file__), "swagger_ui"))


def setup_swagger(app: web.Application,
*,
swagger_from_file: str = None,
Expand All @@ -41,6 +38,7 @@ def setup_swagger(app: web.Application,
swagger_validator_url: str = "",
description: str = "Swagger API definition",
api_version: str = "1.0.0",
ui_version: int = None,
title: str = "Swagger API",
contact: str = "",
swagger_home_decor: FunctionType = None,
Expand All @@ -55,6 +53,11 @@ def setup_swagger(app: web.Application,
_base_swagger_url = _swagger_url.rstrip('/')
_swagger_def_url = '{}/swagger.json'.format(_base_swagger_url)

if ui_version == 3:
STATIC_PATH = abspath(join(dirname(__file__), "swagger_ui3"))
else:
STATIC_PATH = abspath(join(dirname(__file__), "swagger_ui"))

# Build Swagget Info
if swagger_info is None:
if swagger_from_file:
Expand Down
Binary file added aiohttp_swagger/swagger_ui3/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added aiohttp_swagger/swagger_ui3/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions aiohttp_swagger/swagger_ui3/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="##STATIC_PATH##/swagger-ui.css" >
<link rel="icon" type="image/png" href="##STATIC_PATH##/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="##STATIC_PATH##/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="##STATIC_PATH##/swagger-ui-bundle.js"> </script>
<script src="##STATIC_PATH##/swagger-ui-standalone-preset.js"> </script>
<script>
window.onload = function() {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "##SWAGGER_CONFIG##",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
// End Swagger UI call region

window.ui = ui
}
</script>
</body>
</html>
67 changes: 67 additions & 0 deletions aiohttp_swagger/swagger_ui3/oauth2-redirect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!doctype html>
<html lang="en-US">
<body onload="run()">
</body>
</html>
<script>
'use strict';
function run () {
var oauth2 = window.opener.swaggerUIRedirectOauth2;
var sentState = oauth2.state;
var redirectUrl = oauth2.redirectUrl;
var isValid, qp, arr;

if (/code|token|error/.test(window.location.hash)) {
qp = window.location.hash.substring(1);
} else {
qp = location.search.substring(1);
}

arr = qp.split("&")
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';})
qp = qp ? JSON.parse('{' + arr.join() + '}',
function (key, value) {
return key === "" ? value : decodeURIComponent(value)
}
) : {}

isValid = qp.state === sentState

if ((
oauth2.auth.schema.get("flow") === "accessCode"||
oauth2.auth.schema.get("flow") === "authorizationCode"
) && !oauth2.auth.code) {
if (!isValid) {
oauth2.errCb({
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"
});
}

if (qp.code) {
delete oauth2.state;
oauth2.auth.code = qp.code;
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
} else {
let oauthErrorMsg
if (qp.error) {
oauthErrorMsg = "["+qp.error+"]: " +
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
(qp.error_uri ? "More info: "+qp.error_uri : "");
}

oauth2.errCb({
authId: oauth2.auth.name,
source: "auth",
level: "error",
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server"
});
}
} else {
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
}
window.close();
}
</script>
98 changes: 98 additions & 0 deletions aiohttp_swagger/swagger_ui3/swagger-ui-bundle.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions aiohttp_swagger/swagger_ui3/swagger-ui-bundle.js.map

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions aiohttp_swagger/swagger_ui3/swagger-ui-standalone-preset.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions aiohttp_swagger/swagger_ui3/swagger-ui.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions aiohttp_swagger/swagger_ui3/swagger-ui.css.map

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions aiohttp_swagger/swagger_ui3/swagger-ui.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions aiohttp_swagger/swagger_ui3/swagger-ui.js.map

Large diffs are not rendered by default.

0 comments on commit 066d800

Please sign in to comment.