Skip to content

Commit cc0ed79

Browse files
committed
Add custom_css parameter and update Swagger UI and editor
1 parent 21c6270 commit cc0ed79

29 files changed

+125
-99
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ python3 -c "from swagger_ui import supported_list; print(supported_list)"
155155
For details about OAuth2 configuration, see the official documentation [OAuth2 Configuration](https://swagger.io/docs/open-source-tools/swagger-ui/usage/oauth2/).
156156

157157
## Swagger UI
158-
Swagger UI version is `v5.7.2`. see [https://github.com/swagger-api/swagger-ui](https://github.com/swagger-api/swagger-ui).
158+
Swagger UI version is `v5.17.14`. see [https://github.com/swagger-api/swagger-ui](https://github.com/swagger-api/swagger-ui).
159159

160160
## Swagger Editor
161-
Swagger Editor version is `v4.11.1`. see [https://github.com/swagger-api/swagger-editor](https://github.com/swagger-api/swagger-editor).
161+
Swagger Editor version is `v4.13.1`. see [https://github.com/swagger-api/swagger-editor](https://github.com/swagger-api/swagger-editor).
162162

163163
## Update
164164
You can update swagger ui and swagger editor version with

swagger_ui/core.py

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def __init__(self,
3131
config_url=None,
3232
config_spec=None,
3333
config_rel_url=None,
34+
custom_css=None,
3435
url_prefix=r'/api/doc',
3536
title='API doc',
3637
editor=False,
@@ -49,6 +50,7 @@ def __init__(self,
4950
self.config_path = config_path
5051
self.config_spec = config_spec
5152
self.config_rel_url = config_rel_url
53+
self.custom_css = custom_css
5254
assert (self.config or self.config_url or self.config_path or self.config_spec or
5355
self.config_rel_url), \
5456
'One of arguments "config", "config_path", "config_url", "config_spec"' \
@@ -85,6 +87,7 @@ def doc_html(self):
8587
config_url=self.swagger_json_uri_absolute,
8688
parameters=self.parameters,
8789
oauth2_config=self.oauth2_config,
90+
custom_css=self.custom_css,
8891
)
8992

9093
@property

swagger_ui/static/swagger-editor-bundle.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/static/swagger-editor-bundle.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/static/swagger-editor-es-bundle-core.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/static/swagger-editor-es-bundle-core.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/static/swagger-editor-es-bundle.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/static/swagger-editor-standalone-preset.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/static/swagger-editor-standalone-preset.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/static/swagger-editor.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/static/swagger-editor.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/static/swagger-editor.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/static/swagger-editor.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/static/swagger-ui-bundle.js

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/static/swagger-ui-bundle.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/static/swagger-ui-es-bundle-core.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/static/swagger-ui-es-bundle-core.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/static/swagger-ui-es-bundle.js

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/static/swagger-ui-es-bundle.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/static/swagger-ui-standalone-preset.js

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/static/swagger-ui-standalone-preset.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/static/swagger-ui.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/static/swagger-ui.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/static/swagger-ui.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/static/swagger-ui.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_ui/templates/doc.html

+27-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
<!-- HTML for static distribution bundle build -->
22
<!DOCTYPE html>
33
<html lang="en">
4-
<head>
5-
<meta charset="UTF-8">
6-
<title> {{ title }} </title>
7-
<link rel="stylesheet" type="text/css" href="{{ url_prefix }}/static/swagger-ui.css" />
8-
<link rel="stylesheet" type="text/css" href="{{ url_prefix }}/static/index.css" />
9-
<link rel="icon" type="image/png" href="{{ url_prefix }}/static/favicon-32x32.png" sizes="32x32" />
10-
<link rel="icon" type="image/png" href="{{ url_prefix }}/static/favicon-16x16.png" sizes="16x16" />
11-
</head>
12-
13-
<body>
14-
<div id="swagger-ui"></div>
15-
<script src="{{ url_prefix }}/static/swagger-ui-bundle.js" charset="UTF-8"> </script>
16-
<script src="{{ url_prefix }}/static/swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
17-
<script>
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>{{ title }}</title>
7+
<link rel="stylesheet"
8+
type="text/css"
9+
href="{{ url_prefix }}/static/swagger-ui.css" />
10+
<link rel="stylesheet"
11+
type="text/css"
12+
href="{{ url_prefix }}/static/index.css" />
13+
<link rel="icon"
14+
type="image/png"
15+
href="{{ url_prefix }}/static/favicon-32x32.png"
16+
sizes="32x32" />
17+
<link rel="icon"
18+
type="image/png"
19+
href="{{ url_prefix }}/static/favicon-16x16.png"
20+
sizes="16x16" />
21+
{% if custom_css %}<link rel="stylesheet" type="text/css" href="{{ custom_css }}" />{% endif %}
22+
</head>
23+
<body>
24+
<div id="swagger-ui"></div>
25+
<script src="{{ url_prefix }}/static/swagger-ui-bundle.js" charset="UTF-8"> </script>
26+
<script src="{{ url_prefix }}/static/swagger-ui-standalone-preset.js"
27+
charset="UTF-8"></script>
28+
<script>
1829
window.onload = function() {
1930
const ui = SwaggerUIBundle({
2031
{%- for key, value in parameters.items() %}
@@ -32,6 +43,6 @@
3243

3344
window.ui = ui;
3445
};
35-
</script>
36-
</body>
46+
</script>
47+
</body>
3748
</html>

swagger_ui/templates/editor.html

+54-53
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<!DOCTYPE html>
22
<!-- HTML for static distribution bundle build -->
33
<html lang="en">
4-
<head>
5-
<meta charset="UTF-8">
6-
<title> {{ title }} </title>
7-
<style>
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>{{ title }}</title>
7+
<!-- Google Tag Manager -->
8+
<style>
89
* {
910
box-sizing: border-box;
1011
}
@@ -37,17 +38,23 @@
3738
overflow-y: scroll;
3839
}
3940

40-
</style>
41-
<link href="{{ url_prefix }}/static/swagger-editor.css" rel="stylesheet">
42-
<link rel="icon" type="image/png" href="{{ url_prefix }}/static/favicon-32x32.png" sizes="32x32" />
43-
<link rel="icon" type="image/png" href="{{ url_prefix }}/static/favicon-16x16.png" sizes="16x16" />
44-
</head>
45-
46-
<body>
47-
<div id="swagger-editor"></div>
48-
<script src="{{ url_prefix }}/static/swagger-editor-bundle.js"> </script>
49-
<script src="{{ url_prefix }}/static/swagger-editor-standalone-preset.js"> </script>
50-
<script>
41+
</style>
42+
<link href="{{ url_prefix }}/static/swagger-editor.css" rel="stylesheet">
43+
<link rel="icon"
44+
type="image/png"
45+
href="{{ url_prefix }}/static/favicon-32x32.png"
46+
sizes="32x32" />
47+
<link rel="icon"
48+
type="image/png"
49+
href="{{ url_prefix }}/static/favicon-16x16.png"
50+
sizes="16x16" />
51+
</head>
52+
<body>
53+
<!-- Google Tag Manager (noscript) -->
54+
<div id="swagger-editor"></div>
55+
<script src="{{ url_prefix }}/static/swagger-editor-bundle.js"> </script>
56+
<script src="{{ url_prefix }}/static/swagger-editor-standalone-preset.js"> </script>
57+
<script>
5158
window.onload = function() {
5259
// Build a system
5360
const editor = SwaggerEditorBundle({
@@ -61,42 +68,36 @@
6168

6269
window.editor = editor
6370
}
64-
</script>
65-
66-
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position:absolute;width:0;height:0">
67-
<defs>
68-
<symbol viewBox="0 0 20 20" id="unlocked">
69-
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>
70-
</symbol>
71-
72-
<symbol viewBox="0 0 20 20" id="locked">
73-
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z"/>
74-
</symbol>
75-
76-
<symbol viewBox="0 0 20 20" id="close">
77-
<path d="M14.348 14.849c-.469.469-1.229.469-1.697 0L10 11.819l-2.651 3.029c-.469.469-1.229.469-1.697 0-.469-.469-.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-.469-.469-.469-1.228 0-1.697.469-.469 1.228-.469 1.697 0L10 8.183l2.651-3.031c.469-.469 1.228-.469 1.697 0 .469.469.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c.469.469.469 1.229 0 1.698z"/>
78-
</symbol>
79-
80-
<symbol viewBox="0 0 20 20" id="large-arrow">
81-
<path d="M13.25 10L6.109 2.58c-.268-.27-.268-.707 0-.979.268-.27.701-.27.969 0l7.83 7.908c.268.271.268.709 0 .979l-7.83 7.908c-.268.271-.701.27-.969 0-.268-.269-.268-.707 0-.979L13.25 10z"/>
82-
</symbol>
83-
84-
<symbol viewBox="0 0 20 20" id="large-arrow-down">
85-
<path d="M17.418 6.109c.272-.268.709-.268.979 0s.271.701 0 .969l-7.908 7.83c-.27.268-.707.268-.979 0l-7.908-7.83c-.27-.268-.27-.701 0-.969.271-.268.709-.268.979 0L10 13.25l7.418-7.141z"/>
86-
</symbol>
87-
88-
89-
<symbol viewBox="0 0 24 24" id="jump-to">
90-
<path d="M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z"/>
91-
</symbol>
92-
93-
<symbol viewBox="0 0 24 24" id="expand">
94-
<path d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z"/>
95-
</symbol>
96-
97-
</defs>
98-
</svg>
99-
100-
</body>
101-
71+
</script>
72+
<svg xmlns="http://www.w3.org/2000/svg"
73+
xmlns:xlink="http://www.w3.org/1999/xlink"
74+
style="position:absolute;
75+
width:0;
76+
height:0">
77+
<defs>
78+
<symbol viewBox="0 0 20 20" id="unlocked">
79+
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z">
80+
</path>
81+
</symbol>
82+
<symbol viewBox="0 0 20 20" id="locked">
83+
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z" />
84+
</symbol>
85+
<symbol viewBox="0 0 20 20" id="close">
86+
<path d="M14.348 14.849c-.469.469-1.229.469-1.697 0L10 11.819l-2.651 3.029c-.469.469-1.229.469-1.697 0-.469-.469-.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-.469-.469-.469-1.228 0-1.697.469-.469 1.228-.469 1.697 0L10 8.183l2.651-3.031c.469-.469 1.228-.469 1.697 0 .469.469.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c.469.469.469 1.229 0 1.698z" />
87+
</symbol>
88+
<symbol viewBox="0 0 20 20" id="large-arrow">
89+
<path d="M13.25 10L6.109 2.58c-.268-.27-.268-.707 0-.979.268-.27.701-.27.969 0l7.83 7.908c.268.271.268.709 0 .979l-7.83 7.908c-.268.271-.701.27-.969 0-.268-.269-.268-.707 0-.979L13.25 10z" />
90+
</symbol>
91+
<symbol viewBox="0 0 20 20" id="large-arrow-down">
92+
<path d="M17.418 6.109c.272-.268.709-.268.979 0s.271.701 0 .969l-7.908 7.83c-.27.268-.707.268-.979 0l-7.908-7.83c-.27-.268-.27-.701 0-.969.271-.268.709-.268.979 0L10 13.25l7.418-7.141z" />
93+
</symbol>
94+
<symbol viewBox="0 0 24 24" id="jump-to">
95+
<path d="M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z" />
96+
</symbol>
97+
<symbol viewBox="0 0 24 24" id="expand">
98+
<path d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z" />
99+
</symbol>
100+
</defs>
101+
</svg>
102+
</body>
102103
</html>

tools/update.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import shutil
66
import tarfile
77
from pathlib import Path
8+
from djlint.reformat import formatter
9+
from djlint import Config
810

911
import requests
1012

@@ -49,7 +51,8 @@ def detect_latest_release(repo):
4951
print('detect latest release')
5052
resp = requests.get(
5153
'https://api.github.com/repos/{}/releases/latest'.format(repo),
52-
timeout=120)
54+
timeout=120
55+
)
5356
latest = json.loads(resp.text)
5457
tag = latest['tag_name']
5558
print('{} latest version is {}'.format(repo, tag))
@@ -134,9 +137,15 @@ def replace_html_content():
134137
html = re.sub(r'<script .*/swagger-initializer.js".*</script>',
135138
'<script>\n{}\n</script>'.format(DOC_HTML_JAVASCRIPT),
136139
html)
140+
if 'href="{{ custom_css }}"' not in html:
141+
html = re.sub(
142+
r'</head>',
143+
'{% if custom_css %}<link rel="stylesheet" type="text/css" href="{{ custom_css }}" />{% endif %}</head>',
144+
html
145+
)
137146

138147
with html_path.open('w') as html_file:
139-
html_file.write(html)
148+
html_file.write(formatter(Config("-"), html))
140149

141150

142151
def replace_readme(ui_version, editor_version):

tox.ini

+5
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ commands =
1313
commands =
1414
pip install -r test/requirements.txt
1515
pytest -s test/
16+
17+
[testenv:update]
18+
commands =
19+
pip install requests djlint
20+
python tools/update.py --ui --editor

0 commit comments

Comments
 (0)