flask-openapi-swagger 5.31.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- flask_openapi_swagger-5.31.0/.gitignore +141 -0
- flask_openapi_swagger-5.31.0/PKG-INFO +22 -0
- flask_openapi_swagger-5.31.0/flask_openapi_swagger/__init__.py +3 -0
- flask_openapi_swagger-5.31.0/flask_openapi_swagger/__version__.py +3 -0
- flask_openapi_swagger-5.31.0/flask_openapi_swagger/plugins.py +45 -0
- flask_openapi_swagger-5.31.0/flask_openapi_swagger/templates/__init__.py +155 -0
- flask_openapi_swagger-5.31.0/flask_openapi_swagger/templates/swagger/css/swagger-ui.css +3 -0
- flask_openapi_swagger-5.31.0/flask_openapi_swagger/templates/swagger/images/swagger.svg +13 -0
- flask_openapi_swagger-5.31.0/flask_openapi_swagger/templates/swagger/js/swagger-ui-bundle.js +2 -0
- flask_openapi_swagger-5.31.0/flask_openapi_swagger/templates/swagger/js/swagger-ui-standalone-preset.js +2 -0
- flask_openapi_swagger-5.31.0/pyproject.toml +51 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
### Python template
|
|
2
|
+
# Byte-compiled / optimized / DLL files
|
|
3
|
+
__pycache__/
|
|
4
|
+
*.py[cod]
|
|
5
|
+
*$py.class
|
|
6
|
+
|
|
7
|
+
# C extensions
|
|
8
|
+
*.so
|
|
9
|
+
|
|
10
|
+
# Distribution / packaging
|
|
11
|
+
.Python
|
|
12
|
+
build/
|
|
13
|
+
develop-eggs/
|
|
14
|
+
dist/
|
|
15
|
+
downloads/
|
|
16
|
+
eggs/
|
|
17
|
+
.eggs/
|
|
18
|
+
lib/
|
|
19
|
+
lib64/
|
|
20
|
+
parts/
|
|
21
|
+
sdist/
|
|
22
|
+
var/
|
|
23
|
+
wheels/
|
|
24
|
+
share/python-wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
MANIFEST
|
|
29
|
+
|
|
30
|
+
# PyInstaller
|
|
31
|
+
# Usually these files are written by a python script from a template
|
|
32
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
33
|
+
*.manifest
|
|
34
|
+
*.spec
|
|
35
|
+
|
|
36
|
+
# Installer logs
|
|
37
|
+
pip-log.txt
|
|
38
|
+
pip-delete-this-directory.txt
|
|
39
|
+
|
|
40
|
+
# Unit test / coverage reports
|
|
41
|
+
htmlcov/
|
|
42
|
+
.tox/
|
|
43
|
+
.nox/
|
|
44
|
+
.coverage
|
|
45
|
+
.coverage.*
|
|
46
|
+
.cache
|
|
47
|
+
nosetests.xml
|
|
48
|
+
coverage.xml
|
|
49
|
+
*.cover
|
|
50
|
+
*.py,cover
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
.pybuilder/
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
88
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
89
|
+
# .python-version
|
|
90
|
+
|
|
91
|
+
# pipenv
|
|
92
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
93
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
94
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
95
|
+
# install all needed dependencies.
|
|
96
|
+
#Pipfile.lock
|
|
97
|
+
|
|
98
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
|
99
|
+
__pypackages__/
|
|
100
|
+
|
|
101
|
+
# Celery stuff
|
|
102
|
+
celerybeat-schedule
|
|
103
|
+
celerybeat.pid
|
|
104
|
+
|
|
105
|
+
# SageMath parsed files
|
|
106
|
+
*.sage.py
|
|
107
|
+
|
|
108
|
+
# Environments
|
|
109
|
+
.env
|
|
110
|
+
.venv
|
|
111
|
+
env/
|
|
112
|
+
venv/
|
|
113
|
+
ENV/
|
|
114
|
+
env.bak/
|
|
115
|
+
venv.bak/
|
|
116
|
+
|
|
117
|
+
# Spyder project settings
|
|
118
|
+
.spyderproject
|
|
119
|
+
.spyproject
|
|
120
|
+
|
|
121
|
+
# Rope project settings
|
|
122
|
+
.ropeproject
|
|
123
|
+
|
|
124
|
+
# mkdocs documentation
|
|
125
|
+
/site
|
|
126
|
+
|
|
127
|
+
# mypy
|
|
128
|
+
.mypy_cache/
|
|
129
|
+
.dmypy.json
|
|
130
|
+
dmypy.json
|
|
131
|
+
|
|
132
|
+
# Pyre type checker
|
|
133
|
+
.pyre/
|
|
134
|
+
|
|
135
|
+
# pytype static type analyzer
|
|
136
|
+
.pytype/
|
|
137
|
+
|
|
138
|
+
# Cython debug symbols
|
|
139
|
+
cython_debug/
|
|
140
|
+
|
|
141
|
+
.idea
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: flask-openapi-swagger
|
|
3
|
+
Version: 5.31.0
|
|
4
|
+
Summary: Provide Swagger UI for flask-openapi.
|
|
5
|
+
Project-URL: Homepage, https://github.com/luolingchun/flask-openapi-plugins/tree/master/flask-openapi-swagger
|
|
6
|
+
Project-URL: Documentation, https://luolingchun.github.io/flask-openapi/latest/Usage/UI_Templates/
|
|
7
|
+
Maintainer-email: llc <luolingchun@outlook.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Environment :: Web Environment
|
|
11
|
+
Classifier: Framework :: Flask
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Requires-Python: >=3.8
|
|
19
|
+
Requires-Dist: flask-openapi
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
Provide Swagger UI for [flask-openapi](https://github.com/luolingchun/flask-openapi).
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# @Author : llc
|
|
3
|
+
# @Time : 2024/4/22 16:13
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
from flask import Blueprint, render_template_string, current_app
|
|
7
|
+
from flask_openapi.plugins import BasePlugin
|
|
8
|
+
|
|
9
|
+
from .templates import swagger_html_string, swagger_oauth2_redirect_html_string
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class RegisterPlugin(BasePlugin):
|
|
13
|
+
name = "swagger"
|
|
14
|
+
display_name = "Swagger"
|
|
15
|
+
|
|
16
|
+
@classmethod
|
|
17
|
+
def register(cls, doc_url: str) -> Blueprint:
|
|
18
|
+
_here = os.path.dirname(__file__)
|
|
19
|
+
template_folder = os.path.join(_here, "templates")
|
|
20
|
+
static_folder = os.path.join(template_folder, cls.name)
|
|
21
|
+
blueprint = Blueprint(
|
|
22
|
+
cls.name,
|
|
23
|
+
__name__,
|
|
24
|
+
template_folder=template_folder,
|
|
25
|
+
static_folder=static_folder
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
blueprint.add_url_rule(
|
|
29
|
+
rule=f"/{cls.name}",
|
|
30
|
+
endpoint=cls.name,
|
|
31
|
+
view_func=lambda: render_template_string(
|
|
32
|
+
current_app.config.get("SWAGGER_HTML_STRING") or swagger_html_string,
|
|
33
|
+
doc_url=doc_url,
|
|
34
|
+
swagger_config=current_app.config.get("SWAGGER_CONFIG"),
|
|
35
|
+
oauth_config=current_app.config.get("OAUTH_CONFIG")
|
|
36
|
+
)
|
|
37
|
+
)
|
|
38
|
+
blueprint.add_url_rule(
|
|
39
|
+
rule=f"/oauth2-redirect.html",
|
|
40
|
+
endpoint="oauth2-redirect",
|
|
41
|
+
view_func=lambda: render_template_string(
|
|
42
|
+
swagger_oauth2_redirect_html_string
|
|
43
|
+
)
|
|
44
|
+
)
|
|
45
|
+
return blueprint
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# @Author : llc
|
|
3
|
+
# @Time : 2024/4/23 14:46
|
|
4
|
+
swagger_html_string = """
|
|
5
|
+
<!DOCTYPE html>
|
|
6
|
+
<html lang="en">
|
|
7
|
+
<head>
|
|
8
|
+
<meta charset="UTF-8">
|
|
9
|
+
<title>Swagger UI</title>
|
|
10
|
+
<link rel="shortcut icon" href="swagger/images/swagger.svg">
|
|
11
|
+
<link rel="stylesheet" type="text/css" href="swagger/css/swagger-ui.css">
|
|
12
|
+
<style>
|
|
13
|
+
html {
|
|
14
|
+
box-sizing: border-box;
|
|
15
|
+
overflow: -moz-scrollbars-vertical;
|
|
16
|
+
overflow-y: scroll;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
*, *:before, *:after {
|
|
20
|
+
box-sizing: inherit;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
body {
|
|
24
|
+
margin: 0;
|
|
25
|
+
background: #fafafa;
|
|
26
|
+
}
|
|
27
|
+
</style>
|
|
28
|
+
</head>
|
|
29
|
+
<body>
|
|
30
|
+
<div id="swagger-ui"></div>
|
|
31
|
+
<script src="swagger/js/swagger-ui-bundle.js"></script>
|
|
32
|
+
<script src="swagger/js/swagger-ui-standalone-preset.js"></script>
|
|
33
|
+
<script>
|
|
34
|
+
const swagger_config = JSON.parse(`{{ swagger_config|default('{}')|tojson }}`);
|
|
35
|
+
url = new URL("{{doc_url}}", window.location.href).href;
|
|
36
|
+
window.onload = function () {
|
|
37
|
+
// Begin Swagger UI call region
|
|
38
|
+
window.ui = SwaggerUIBundle({
|
|
39
|
+
...{
|
|
40
|
+
url: url,
|
|
41
|
+
dom_id: "#swagger-ui",
|
|
42
|
+
deepLinking: true,
|
|
43
|
+
presets: [
|
|
44
|
+
SwaggerUIBundle.presets.apis,
|
|
45
|
+
SwaggerUIStandalonePreset
|
|
46
|
+
],
|
|
47
|
+
plugins: [
|
|
48
|
+
SwaggerUIBundle.plugins.DownloadUrl
|
|
49
|
+
],
|
|
50
|
+
layout: "StandaloneLayout",
|
|
51
|
+
showExtensions: true,
|
|
52
|
+
showCommonExtensions: true
|
|
53
|
+
},
|
|
54
|
+
...swagger_config
|
|
55
|
+
})
|
|
56
|
+
// End Swagger UI call region
|
|
57
|
+
const oauthConfig = {{ oauth_config|tojson }};
|
|
58
|
+
if (oauthConfig != null) {
|
|
59
|
+
window.ui.initOAuth({
|
|
60
|
+
clientId: oauthConfig.clientId,
|
|
61
|
+
clientSecret: oauthConfig.clientSecret,
|
|
62
|
+
realm: oauthConfig.realm,
|
|
63
|
+
appName: oauthConfig.appName,
|
|
64
|
+
scopeSeparator: oauthConfig.scopeSeparator,
|
|
65
|
+
scopes: oauthConfig.scopes,
|
|
66
|
+
additionalQueryStringParams: oauthConfig.additionalQueryStringParams,
|
|
67
|
+
usePkceWithAuthorizationCodeGrant: oauthConfig.usePkceWithAuthorizationCodeGrant
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
</script>
|
|
72
|
+
</body>
|
|
73
|
+
</html>
|
|
74
|
+
"""
|
|
75
|
+
swagger_oauth2_redirect_html_string = """
|
|
76
|
+
<!doctype html>
|
|
77
|
+
<html lang="en-US">
|
|
78
|
+
<head>
|
|
79
|
+
<title>Swagger UI: OAuth2 Redirect</title>
|
|
80
|
+
</head>
|
|
81
|
+
<body>
|
|
82
|
+
<script>
|
|
83
|
+
'use strict';
|
|
84
|
+
function run () {
|
|
85
|
+
var oauth2 = window.opener.swaggerUIRedirectOauth2;
|
|
86
|
+
var sentState = oauth2.state;
|
|
87
|
+
var redirectUrl = oauth2.redirectUrl;
|
|
88
|
+
var isValid, qp, arr;
|
|
89
|
+
|
|
90
|
+
if (/code|token|error/.test(window.location.hash)) {
|
|
91
|
+
qp = window.location.hash.substring(1).replace('?', '&');
|
|
92
|
+
} else {
|
|
93
|
+
qp = location.search.substring(1);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
arr = qp.split("&");
|
|
97
|
+
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';});
|
|
98
|
+
qp = qp ? JSON.parse('{' + arr.join() + '}',
|
|
99
|
+
function (key, value) {
|
|
100
|
+
return key === "" ? value : decodeURIComponent(value);
|
|
101
|
+
}
|
|
102
|
+
) : {};
|
|
103
|
+
|
|
104
|
+
isValid = qp.state === sentState;
|
|
105
|
+
|
|
106
|
+
if ((
|
|
107
|
+
oauth2.auth.schema.get("flow") === "accessCode" ||
|
|
108
|
+
oauth2.auth.schema.get("flow") === "authorizationCode" ||
|
|
109
|
+
oauth2.auth.schema.get("flow") === "authorization_code"
|
|
110
|
+
) && !oauth2.auth.code) {
|
|
111
|
+
if (!isValid) {
|
|
112
|
+
oauth2.errCb({
|
|
113
|
+
authId: oauth2.auth.name,
|
|
114
|
+
source: "auth",
|
|
115
|
+
level: "warning",
|
|
116
|
+
message: "Authorization may be unsafe, passed state was changed in server. The passed state wasn't returned from auth server."
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (qp.code) {
|
|
121
|
+
delete oauth2.state;
|
|
122
|
+
oauth2.auth.code = qp.code;
|
|
123
|
+
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
|
|
124
|
+
} else {
|
|
125
|
+
let oauthErrorMsg;
|
|
126
|
+
if (qp.error) {
|
|
127
|
+
oauthErrorMsg = "["+qp.error+"]: " +
|
|
128
|
+
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
|
|
129
|
+
(qp.error_uri ? "More info: "+qp.error_uri : "");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
oauth2.errCb({
|
|
133
|
+
authId: oauth2.auth.name,
|
|
134
|
+
source: "auth",
|
|
135
|
+
level: "error",
|
|
136
|
+
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server."
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
|
|
141
|
+
}
|
|
142
|
+
window.close();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (document.readyState !== 'loading') {
|
|
146
|
+
run();
|
|
147
|
+
} else {
|
|
148
|
+
document.addEventListener('DOMContentLoaded', function () {
|
|
149
|
+
run();
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
</script>
|
|
153
|
+
</body>
|
|
154
|
+
</html>
|
|
155
|
+
"""
|