Commit 066d800e authored by Goran Pavlovic's avatar Goran Pavlovic
Browse files

Merge branch 'alex/swagger-ui3' of...

Merge branch 'alex/swagger-ui3' of https://github.com/Alexei-Kornienko/aiohttp-swagger into Alexei-Kornienko-alex/swagger-ui3
parents a749d4b5 dacb786f
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
......
......@@ -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,
......@@ -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,
......@@ -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:
......
<!-- 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>
<!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>
This diff is collapsed.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment