Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom_css parameter and update Swagger UI and editor #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ python3 -c "from swagger_ui import supported_list; print(supported_list)"
For details about OAuth2 configuration, see the official documentation [OAuth2 Configuration](https://swagger.io/docs/open-source-tools/swagger-ui/usage/oauth2/).

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

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

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

```bash
python3 tools/update.py --ui --editor
tox -e update
```
3 changes: 3 additions & 0 deletions swagger_ui/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self,
config_url=None,
config_spec=None,
config_rel_url=None,
custom_css=None,
url_prefix=r'/api/doc',
title='API doc',
editor=False,
Expand All @@ -49,6 +50,7 @@ def __init__(self,
self.config_path = config_path
self.config_spec = config_spec
self.config_rel_url = config_rel_url
self.custom_css = custom_css
assert (self.config or self.config_url or self.config_path or self.config_spec or
self.config_rel_url), \
'One of arguments "config", "config_path", "config_url", "config_spec"' \
Expand Down Expand Up @@ -85,6 +87,7 @@ def doc_html(self):
config_url=self.swagger_json_uri_absolute,
parameters=self.parameters,
oauth2_config=self.oauth2_config,
custom_css=self.custom_css,
)

@property
Expand Down
2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-editor-bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-editor-bundle.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-editor-es-bundle-core.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-editor-es-bundle-core.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-editor-es-bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-editor-standalone-preset.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-editor-standalone-preset.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-editor.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-editor.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-editor.js.map

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions swagger_ui/static/swagger-ui-bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-ui-bundle.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-ui-es-bundle-core.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-ui-es-bundle-core.js.map

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions swagger_ui/static/swagger-ui-es-bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-ui-es-bundle.js.map

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions swagger_ui/static/swagger-ui-standalone-preset.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-ui-standalone-preset.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-ui.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-ui.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-ui.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion swagger_ui/static/swagger-ui.js.map

Large diffs are not rendered by default.

43 changes: 27 additions & 16 deletions swagger_ui/templates/doc.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> {{ title }} </title>
<link rel="stylesheet" type="text/css" href="{{ url_prefix }}/static/swagger-ui.css" />
<link rel="stylesheet" type="text/css" href="{{ url_prefix }}/static/index.css" />
<link rel="icon" type="image/png" href="{{ url_prefix }}/static/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="{{ url_prefix }}/static/favicon-16x16.png" sizes="16x16" />
</head>

<body>
<div id="swagger-ui"></div>
<script src="{{ url_prefix }}/static/swagger-ui-bundle.js" charset="UTF-8"> </script>
<script src="{{ url_prefix }}/static/swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
<script>
<head>
<meta charset="UTF-8">
<title>{{ title }}</title>
<link rel="stylesheet"
type="text/css"
href="{{ url_prefix }}/static/swagger-ui.css" />
<link rel="stylesheet"
type="text/css"
href="{{ url_prefix }}/static/index.css" />
<link rel="icon"
type="image/png"
href="{{ url_prefix }}/static/favicon-32x32.png"
sizes="32x32" />
<link rel="icon"
type="image/png"
href="{{ url_prefix }}/static/favicon-16x16.png"
sizes="16x16" />
{% if custom_css %}<link rel="stylesheet" type="text/css" href="{{ custom_css }}" />{% endif %}
</head>
<body>
<div id="swagger-ui"></div>
<script src="{{ url_prefix }}/static/swagger-ui-bundle.js" charset="UTF-8"> </script>
<script src="{{ url_prefix }}/static/swagger-ui-standalone-preset.js"
charset="UTF-8"></script>
<script>
window.onload = function() {
const ui = SwaggerUIBundle({
{%- for key, value in parameters.items() %}
Expand All @@ -32,6 +43,6 @@

window.ui = ui;
};
</script>
</body>
</script>
</body>
</html>
107 changes: 54 additions & 53 deletions swagger_ui/templates/editor.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<!DOCTYPE html>
<!-- HTML for static distribution bundle build -->
<html lang="en">
<head>
<meta charset="UTF-8">
<title> {{ title }} </title>
<style>
<head>
<meta charset="UTF-8">
<title>{{ title }}</title>
<!-- Google Tag Manager -->
<style>
* {
box-sizing: border-box;
}
Expand Down Expand Up @@ -37,17 +38,23 @@
overflow-y: scroll;
}

</style>
<link href="{{ url_prefix }}/static/swagger-editor.css" rel="stylesheet">
<link rel="icon" type="image/png" href="{{ url_prefix }}/static/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="{{ url_prefix }}/static/favicon-16x16.png" sizes="16x16" />
</head>

<body>
<div id="swagger-editor"></div>
<script src="{{ url_prefix }}/static/swagger-editor-bundle.js"> </script>
<script src="{{ url_prefix }}/static/swagger-editor-standalone-preset.js"> </script>
<script>
</style>
<link href="{{ url_prefix }}/static/swagger-editor.css" rel="stylesheet">
<link rel="icon"
type="image/png"
href="{{ url_prefix }}/static/favicon-32x32.png"
sizes="32x32" />
<link rel="icon"
type="image/png"
href="{{ url_prefix }}/static/favicon-16x16.png"
sizes="16x16" />
</head>
<body>
<!-- Google Tag Manager (noscript) -->
<div id="swagger-editor"></div>
<script src="{{ url_prefix }}/static/swagger-editor-bundle.js"> </script>
<script src="{{ url_prefix }}/static/swagger-editor-standalone-preset.js"> </script>
<script>
window.onload = function() {
// Build a system
const editor = SwaggerEditorBundle({
Expand All @@ -61,42 +68,36 @@

window.editor = editor
}
</script>

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position:absolute;width:0;height:0">
<defs>
<symbol viewBox="0 0 20 20" id="unlocked">
<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>
</symbol>

<symbol viewBox="0 0 20 20" id="locked">
<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"/>
</symbol>

<symbol viewBox="0 0 20 20" id="close">
<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"/>
</symbol>

<symbol viewBox="0 0 20 20" id="large-arrow">
<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"/>
</symbol>

<symbol viewBox="0 0 20 20" id="large-arrow-down">
<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"/>
</symbol>


<symbol viewBox="0 0 24 24" id="jump-to">
<path d="M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z"/>
</symbol>

<symbol viewBox="0 0 24 24" id="expand">
<path d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z"/>
</symbol>

</defs>
</svg>

</body>

</script>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
style="position:absolute;
width:0;
height:0">
<defs>
<symbol viewBox="0 0 20 20" id="unlocked">
<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>
</symbol>
<symbol viewBox="0 0 20 20" id="locked">
<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" />
</symbol>
<symbol viewBox="0 0 20 20" id="close">
<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" />
</symbol>
<symbol viewBox="0 0 20 20" id="large-arrow">
<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" />
</symbol>
<symbol viewBox="0 0 20 20" id="large-arrow-down">
<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" />
</symbol>
<symbol viewBox="0 0 24 24" id="jump-to">
<path d="M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z" />
</symbol>
<symbol viewBox="0 0 24 24" id="expand">
<path d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z" />
</symbol>
</defs>
</svg>
</body>
</html>
13 changes: 11 additions & 2 deletions tools/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import shutil
import tarfile
from pathlib import Path
from djlint.reformat import formatter
from djlint import Config

import requests

Expand Down Expand Up @@ -49,7 +51,8 @@ def detect_latest_release(repo):
print('detect latest release')
resp = requests.get(
'https://api.github.com/repos/{}/releases/latest'.format(repo),
timeout=120)
timeout=120
)
latest = json.loads(resp.text)
tag = latest['tag_name']
print('{} latest version is {}'.format(repo, tag))
Expand Down Expand Up @@ -134,9 +137,15 @@ def replace_html_content():
html = re.sub(r'<script .*/swagger-initializer.js".*</script>',
'<script>\n{}\n</script>'.format(DOC_HTML_JAVASCRIPT),
html)
if 'href="{{ custom_css }}"' not in html:
html = re.sub(
r'</head>',
'{% if custom_css %}<link rel="stylesheet" type="text/css" href="{{ custom_css }}" />{% endif %}</head>',
html
)

with html_path.open('w') as html_file:
html_file.write(html)
html_file.write(formatter(Config("-"), html))


def replace_readme(ui_version, editor_version):
Expand Down
5 changes: 5 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ commands =
commands =
pip install -r test/requirements.txt
pytest -s test/

[testenv:update]
commands =
pip install requests djlint
python tools/update.py --ui --editor