star-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.
- star_openapi_swagger-5.31.0/.gitignore +141 -0
- star_openapi_swagger-5.31.0/PKG-INFO +22 -0
- star_openapi_swagger-5.31.0/pyproject.toml +45 -0
- star_openapi_swagger-5.31.0/star_openapi_swagger/__init__.py +0 -0
- star_openapi_swagger-5.31.0/star_openapi_swagger/__version__.py +3 -0
- star_openapi_swagger-5.31.0/star_openapi_swagger/plugins.py +53 -0
- star_openapi_swagger-5.31.0/star_openapi_swagger/templates/__init__.py +152 -0
- star_openapi_swagger-5.31.0/star_openapi_swagger/templates/swagger/css/swagger-ui.css +3 -0
- star_openapi_swagger-5.31.0/star_openapi_swagger/templates/swagger/images/swagger.svg +13 -0
- star_openapi_swagger-5.31.0/star_openapi_swagger/templates/swagger/js/swagger-ui-bundle.js +2 -0
- star_openapi_swagger-5.31.0/star_openapi_swagger/templates/swagger/js/swagger-ui-standalone-preset.js +2 -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: star-openapi-swagger
|
|
3
|
+
Version: 5.31.0
|
|
4
|
+
Summary: Provide Swagger UI for star-openapi.
|
|
5
|
+
Project-URL: Homepage, https://github.com/luolingchun/star-openapi-plugins/tree/master/star-openapi-swagger
|
|
6
|
+
Project-URL: Documentation, https://luolingchun.github.io/star-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.11
|
|
19
|
+
Requires-Dist: star-openapi
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
Provide Swagger UI for [star-openapi](https://github.com/luolingchun/star-openapi).
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "star-openapi-swagger"
|
|
3
|
+
description = "Provide Swagger UI for star-openapi."
|
|
4
|
+
readme = { text = "Provide Swagger UI for [star-openapi](https://github.com/luolingchun/star-openapi).", content-type = "text/markdown" }
|
|
5
|
+
license = { text = "MIT" }
|
|
6
|
+
maintainers = [{ name = "llc", email = "luolingchun@outlook.com" }]
|
|
7
|
+
classifiers = [
|
|
8
|
+
# "Development Status :: 1 - Planning",
|
|
9
|
+
# "Development Status :: 2 - Pre-Alpha",
|
|
10
|
+
# "Development Status :: 3 - Alpha",
|
|
11
|
+
# "Development Status :: 4 - Beta",
|
|
12
|
+
"Development Status :: 5 - Production/Stable",
|
|
13
|
+
# "Development Status :: 6 - Mature",
|
|
14
|
+
# "Development Status :: 7 - Inactive",
|
|
15
|
+
"Environment :: Web Environment",
|
|
16
|
+
"Framework :: Flask",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3 :: Only"
|
|
23
|
+
]
|
|
24
|
+
requires-python = ">=3.11"
|
|
25
|
+
dependencies = ["star-openapi"]
|
|
26
|
+
dynamic = ["version"]
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/luolingchun/star-openapi-plugins/tree/master/star-openapi-swagger"
|
|
30
|
+
Documentation = "https://luolingchun.github.io/star-openapi/latest/Usage/UI_Templates/"
|
|
31
|
+
|
|
32
|
+
[project.entry-points."star_openapi.plugins"]
|
|
33
|
+
register = "star_openapi_swagger.plugins.RegisterPlugin"
|
|
34
|
+
|
|
35
|
+
[build-system]
|
|
36
|
+
requires = ["hatchling"]
|
|
37
|
+
build-backend = "hatchling.build"
|
|
38
|
+
|
|
39
|
+
[tool.hatch.version]
|
|
40
|
+
path = "star_openapi_swagger/__version__.py"
|
|
41
|
+
|
|
42
|
+
[tool.hatch.build.targets.sdist]
|
|
43
|
+
include = [
|
|
44
|
+
"/star_openapi_swagger"
|
|
45
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import os.path
|
|
2
|
+
|
|
3
|
+
from jinja2 import Template
|
|
4
|
+
from star_openapi.plugins import BasePlugin
|
|
5
|
+
from starlette.responses import HTMLResponse
|
|
6
|
+
from starlette.routing import Route, Mount
|
|
7
|
+
from starlette.staticfiles import StaticFiles
|
|
8
|
+
|
|
9
|
+
from .templates import swagger_html_string, swagger_oauth2_redirect_html_string
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class RegisterPlugin(BasePlugin):
|
|
13
|
+
def __init__(self):
|
|
14
|
+
self.name = "swagger"
|
|
15
|
+
self.display_name = "Swagger"
|
|
16
|
+
self.doc_url = "/openapi.json"
|
|
17
|
+
|
|
18
|
+
def swagger_endpoint(self, request):
|
|
19
|
+
template = Template(request.app.config.get("SWAGGER_HTML_STRING") or swagger_html_string)
|
|
20
|
+
return HTMLResponse(
|
|
21
|
+
content=template.render(
|
|
22
|
+
{
|
|
23
|
+
"doc_url": self.doc_url,
|
|
24
|
+
"swagger_config": request.app.config.get("SWAGGER_CONFIG"),
|
|
25
|
+
"oauth_config": request.app.config.get("OAUTH_CONFIG")
|
|
26
|
+
}
|
|
27
|
+
)
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
@staticmethod
|
|
31
|
+
def oauth2_endpoint(_request):
|
|
32
|
+
template = Template(swagger_oauth2_redirect_html_string)
|
|
33
|
+
return HTMLResponse(
|
|
34
|
+
content=template.render()
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
def register(self, doc_url: str) -> list[Route]:
|
|
38
|
+
self.doc_url = doc_url
|
|
39
|
+
static_folder = os.path.join(os.path.dirname(__file__), "templates", "swagger")
|
|
40
|
+
|
|
41
|
+
routes = [
|
|
42
|
+
Route(
|
|
43
|
+
f"/{self.name}",
|
|
44
|
+
endpoint=self.swagger_endpoint
|
|
45
|
+
),
|
|
46
|
+
Route(
|
|
47
|
+
f"/oauth2-redirect.html",
|
|
48
|
+
endpoint=self.oauth2_endpoint
|
|
49
|
+
),
|
|
50
|
+
Mount("/swagger", app=StaticFiles(directory=static_folder), name="static"),
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
return routes
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
swagger_html_string = """
|
|
2
|
+
<!DOCTYPE html>
|
|
3
|
+
<html lang="en">
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<title>Swagger UI</title>
|
|
7
|
+
<link rel="shortcut icon" href="swagger/images/swagger.svg">
|
|
8
|
+
<link rel="stylesheet" type="text/css" href="swagger/css/swagger-ui.css">
|
|
9
|
+
<style>
|
|
10
|
+
html {
|
|
11
|
+
box-sizing: border-box;
|
|
12
|
+
overflow: -moz-scrollbars-vertical;
|
|
13
|
+
overflow-y: scroll;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
*, *:before, *:after {
|
|
17
|
+
box-sizing: inherit;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
body {
|
|
21
|
+
margin: 0;
|
|
22
|
+
background: #fafafa;
|
|
23
|
+
}
|
|
24
|
+
</style>
|
|
25
|
+
</head>
|
|
26
|
+
<body>
|
|
27
|
+
<div id="swagger-ui"></div>
|
|
28
|
+
<script src="swagger/js/swagger-ui-bundle.js"></script>
|
|
29
|
+
<script src="swagger/js/swagger-ui-standalone-preset.js"></script>
|
|
30
|
+
<script>
|
|
31
|
+
const swagger_config = JSON.parse(`{{ swagger_config|default('{}')|tojson }}`);
|
|
32
|
+
url = new URL("{{doc_url}}", window.location.href).href;
|
|
33
|
+
window.onload = function () {
|
|
34
|
+
// Begin Swagger UI call region
|
|
35
|
+
window.ui = SwaggerUIBundle({
|
|
36
|
+
...{
|
|
37
|
+
url: url,
|
|
38
|
+
dom_id: "#swagger-ui",
|
|
39
|
+
deepLinking: true,
|
|
40
|
+
presets: [
|
|
41
|
+
SwaggerUIBundle.presets.apis,
|
|
42
|
+
SwaggerUIStandalonePreset
|
|
43
|
+
],
|
|
44
|
+
plugins: [
|
|
45
|
+
SwaggerUIBundle.plugins.DownloadUrl
|
|
46
|
+
],
|
|
47
|
+
layout: "StandaloneLayout",
|
|
48
|
+
showExtensions: true,
|
|
49
|
+
showCommonExtensions: true
|
|
50
|
+
},
|
|
51
|
+
...swagger_config
|
|
52
|
+
})
|
|
53
|
+
// End Swagger UI call region
|
|
54
|
+
const oauthConfig = {{ oauth_config|tojson }};
|
|
55
|
+
if (oauthConfig != null) {
|
|
56
|
+
window.ui.initOAuth({
|
|
57
|
+
clientId: oauthConfig.clientId,
|
|
58
|
+
clientSecret: oauthConfig.clientSecret,
|
|
59
|
+
realm: oauthConfig.realm,
|
|
60
|
+
appName: oauthConfig.appName,
|
|
61
|
+
scopeSeparator: oauthConfig.scopeSeparator,
|
|
62
|
+
scopes: oauthConfig.scopes,
|
|
63
|
+
additionalQueryStringParams: oauthConfig.additionalQueryStringParams,
|
|
64
|
+
usePkceWithAuthorizationCodeGrant: oauthConfig.usePkceWithAuthorizationCodeGrant
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
</script>
|
|
69
|
+
</body>
|
|
70
|
+
</html>
|
|
71
|
+
"""
|
|
72
|
+
swagger_oauth2_redirect_html_string = """
|
|
73
|
+
<!doctype html>
|
|
74
|
+
<html lang="en-US">
|
|
75
|
+
<head>
|
|
76
|
+
<title>Swagger UI: OAuth2 Redirect</title>
|
|
77
|
+
</head>
|
|
78
|
+
<body>
|
|
79
|
+
<script>
|
|
80
|
+
'use strict';
|
|
81
|
+
function run () {
|
|
82
|
+
var oauth2 = window.opener.swaggerUIRedirectOauth2;
|
|
83
|
+
var sentState = oauth2.state;
|
|
84
|
+
var redirectUrl = oauth2.redirectUrl;
|
|
85
|
+
var isValid, qp, arr;
|
|
86
|
+
|
|
87
|
+
if (/code|token|error/.test(window.location.hash)) {
|
|
88
|
+
qp = window.location.hash.substring(1).replace('?', '&');
|
|
89
|
+
} else {
|
|
90
|
+
qp = location.search.substring(1);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
arr = qp.split("&");
|
|
94
|
+
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';});
|
|
95
|
+
qp = qp ? JSON.parse('{' + arr.join() + '}',
|
|
96
|
+
function (key, value) {
|
|
97
|
+
return key === "" ? value : decodeURIComponent(value);
|
|
98
|
+
}
|
|
99
|
+
) : {};
|
|
100
|
+
|
|
101
|
+
isValid = qp.state === sentState;
|
|
102
|
+
|
|
103
|
+
if ((
|
|
104
|
+
oauth2.auth.schema.get("flow") === "accessCode" ||
|
|
105
|
+
oauth2.auth.schema.get("flow") === "authorizationCode" ||
|
|
106
|
+
oauth2.auth.schema.get("flow") === "authorization_code"
|
|
107
|
+
) && !oauth2.auth.code) {
|
|
108
|
+
if (!isValid) {
|
|
109
|
+
oauth2.errCb({
|
|
110
|
+
authId: oauth2.auth.name,
|
|
111
|
+
source: "auth",
|
|
112
|
+
level: "warning",
|
|
113
|
+
message: "Authorization may be unsafe, passed state was changed in server. The passed state wasn't returned from auth server."
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (qp.code) {
|
|
118
|
+
delete oauth2.state;
|
|
119
|
+
oauth2.auth.code = qp.code;
|
|
120
|
+
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
|
|
121
|
+
} else {
|
|
122
|
+
let oauthErrorMsg;
|
|
123
|
+
if (qp.error) {
|
|
124
|
+
oauthErrorMsg = "["+qp.error+"]: " +
|
|
125
|
+
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
|
|
126
|
+
(qp.error_uri ? "More info: "+qp.error_uri : "");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
oauth2.errCb({
|
|
130
|
+
authId: oauth2.auth.name,
|
|
131
|
+
source: "auth",
|
|
132
|
+
level: "error",
|
|
133
|
+
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server."
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
} else {
|
|
137
|
+
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
|
|
138
|
+
}
|
|
139
|
+
window.close();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (document.readyState !== 'loading') {
|
|
143
|
+
run();
|
|
144
|
+
} else {
|
|
145
|
+
document.addEventListener('DOMContentLoaded', function () {
|
|
146
|
+
run();
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
</script>
|
|
150
|
+
</body>
|
|
151
|
+
</html>
|
|
152
|
+
"""
|