mirror of
https://github.com/fastapi/fastapi.git
synced 2026-09-14 13:36:21 +08:00
500f2b2ad4
Update the Swagger UI docs to deep link to path operations to share them more easily.
81 lines
1.9 KiB
Python
81 lines
1.9 KiB
Python
from starlette.responses import HTMLResponse
|
|
|
|
|
|
def get_swagger_ui_html(*, openapi_url: str, title: str) -> HTMLResponse:
|
|
return HTMLResponse(
|
|
"""
|
|
<! doctype html>
|
|
<html>
|
|
<head>
|
|
<link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swagger-ui-dist@3/swagger-ui.css">
|
|
<link rel="shortcut icon" href="https://fastapi.tiangolo.com/img/favicon.png">
|
|
<title>
|
|
"""
|
|
+ title
|
|
+ """
|
|
</title>
|
|
</head>
|
|
<body>
|
|
<div id="swagger-ui">
|
|
</div>
|
|
<script src="https://cdn.jsdelivr.net/npm/swagger-ui-dist@3/swagger-ui-bundle.js"></script>
|
|
<!-- `SwaggerUIBundle` is now available on the page -->
|
|
<script>
|
|
|
|
const ui = SwaggerUIBundle({
|
|
url: '"""
|
|
+ openapi_url
|
|
+ """',
|
|
dom_id: '#swagger-ui',
|
|
presets: [
|
|
SwaggerUIBundle.presets.apis,
|
|
SwaggerUIBundle.SwaggerUIStandalonePreset
|
|
],
|
|
layout: "BaseLayout",
|
|
deepLinking: true
|
|
|
|
})
|
|
</script>
|
|
</body>
|
|
</html>
|
|
"""
|
|
)
|
|
|
|
|
|
def get_redoc_html(*, openapi_url: str, title: str) -> HTMLResponse:
|
|
return HTMLResponse(
|
|
"""
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>
|
|
"""
|
|
+ title
|
|
+ """
|
|
</title>
|
|
<!-- needed for adaptive design -->
|
|
<meta charset="utf-8"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">
|
|
<link rel="shortcut icon" href="https://fastapi.tiangolo.com/img/favicon.png">
|
|
|
|
<!--
|
|
ReDoc doesn't change outer page styles
|
|
-->
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<redoc spec-url='"""
|
|
+ openapi_url
|
|
+ """'></redoc>
|
|
<script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"> </script>
|
|
</body>
|
|
</html>
|
|
"""
|
|
)
|