-
Notifications
You must be signed in to change notification settings - Fork 420
/
Copy pathhtml.py
52 lines (47 loc) · 1.04 KB
/
html.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def generate_swagger_html(spec: str, js_url: str, css_url: str) -> str:
"""
Generate Swagger UI HTML page
Parameters
----------
spec: str
The OpenAPI spec in the JSON format
js_url: str
The URL to the Swagger UI JavaScript file
css_url: str
The URL to the Swagger UI CSS file
"""
return f"""
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="{css_url}">
</head>
<body>
<div id="swagger-ui">
Loading...
</div>
</body>
<script src="{js_url}"></script>
<script>
var swaggerUIOptions = {{
dom_id: "#swagger-ui",
docExpansion: "list",
deepLinking: true,
filter: true,
spec: JSON.parse(`
{spec}
`.trim()),
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIBundle.SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
]
}}
var ui = SwaggerUIBundle(swaggerUIOptions)
</script>
</html>
""".strip()