Skip to content

Commit

Permalink
make swagger ui version configurable (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantownsend committed Aug 2, 2023
1 parent dceea26 commit 14e1b1b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions piccolo_api/openapi/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def swagger_ui(
swagger_ui_title: str = "Piccolo Swagger UI",
csrf_cookie_name: t.Optional[str] = DEFAULT_COOKIE_NAME,
csrf_header_name: t.Optional[str] = DEFAULT_HEADER_NAME,
swagger_ui_version: str = "5",
):
"""
Even though ASGI frameworks such as FastAPI and BlackSheep have endpoints
Expand Down Expand Up @@ -53,6 +54,8 @@ def swagger_ui(
The name of the CSRF cookie.
:param csrf_header_name:
The HTTP header name which the CSRF cookie value will be added to.
:param swagger_ui_version:
Which version of Swagger UI to use.
"""

Expand All @@ -68,6 +71,7 @@ def get(self, request: Request):
swagger_ui_title=swagger_ui_title,
csrf_cookie_name=csrf_cookie_name,
csrf_header_name=csrf_header_name,
swagger_ui_version=swagger_ui_version,
)
return HTMLResponse(content=html)

Expand Down
4 changes: 2 additions & 2 deletions piccolo_api/openapi/templates/swagger_ui.html.jinja
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui.css">
<link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swagger-ui-dist@{{ swagger_ui_version }}/swagger-ui.css">
<title>{{ swagger_ui_title }}</title>
</head>

<body>
<div id="swagger-ui">
</div>
<script src="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui-bundle.js"></script>
<script src="https://cdn.jsdelivr.net/npm/swagger-ui-dist@{{ swagger_ui_version }}/swagger-ui-bundle.js"></script>
{% if csrf_cookie_name and csrf_header_name %}
<script src="https://cdn.jsdelivr.net/npm/js-cookie@2.2.1/src/js.cookie.min.js"></script>
{% endif %}
Expand Down

0 comments on commit 14e1b1b

Please sign in to comment.