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

remove inline script (csp) #140

Open
wants to merge 1 commit into
base: main
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
1 change: 1 addition & 0 deletions flask_smorest/spec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def _register_doc_blueprint(self):
__name__,
url_prefix=_add_leading_slash(api_url),
template_folder='./templates',
static_folder='static',
)
# Serve json spec at 'url_prefix/openapi.json' by default
json_path = self._app.config.get(
Expand Down
16 changes: 4 additions & 12 deletions flask_smorest/spec/templates/swagger_ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,10 @@

<script src="{{swagger_ui_url}}swagger-ui-standalone-preset.js"></script>
<script src="{{swagger_ui_url}}swagger-ui-bundle.js"></script>
<script>
window.onload = function() {
const ui = SwaggerUIBundle({
url: "{{ url_for('api-docs.openapi_json') }}",
dom_id: '#swagger-ui-container',
deepLinking: true,
layout: "BaseLayout",
supportedSubmitMethods: [{% for meth in swagger_ui_supported_submit_methods %}"{{meth.lower()}}",{% endfor %}],
})
window.ui = ui
}
</script>

<script id="openapi-url" type="application/json">{{ url_for('api-docs.openapi_json') }}</script>
<script id="supported-submit-methods" type="application/json">{{ swagger_ui_supported_submit_methods|tojson }}</script>
<script type="text/javascript" src={{url_for("api-docs.static", filename="js/swagger-ui-bundle.js")}}></script>

</body>

Expand Down
10 changes: 10 additions & 0 deletions flask_smorest/static/js/swagger-ui-bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
window.onload = function() {
const ui = SwaggerUIBundle({
url: document.getElementById('openapi-url').textContent,
dom_id: '#swagger-ui-container',
deepLinking: true,
layout: "BaseLayout",
supportedSubmitMethods: JSON.parse(document.getElementById('supported-submit-methods').textContent),
})
window.ui = ui
}