feat: add offline swagger docs (#7653)

This commit is contained in:
KX 2025-04-07 04:55:06 +08:00 committed by GitHub
parent f4c9dce211
commit 0ac896a6f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 0 deletions

View file

@ -348,10 +348,12 @@ from fastapi import (
Response,
UploadFile,
status,
applications
)
from fastapi.encoders import jsonable_encoder
from fastapi.middleware.cors import CORSMiddleware
from fastapi.openapi.utils import get_openapi
from fastapi.openapi.docs import get_swagger_ui_html
from fastapi.responses import (
FileResponse,
JSONResponse,
@ -749,6 +751,18 @@ app.add_middleware(
app.add_middleware(PrometheusAuthMiddleware)
swagger_path = os.path.join(current_dir, "swagger")
app.mount("/swagger", StaticFiles(directory=swagger_path), name="swagger")
def swagger_monkey_patch(*args, **kwargs):
return get_swagger_ui_html(
*args,
**kwargs,
swagger_js_url="/swagger/swagger-ui-bundle.js",
swagger_css_url="/swagger/swagger-ui.css",
swagger_favicon_url="/swagger/favicon.png"
)
applications.get_swagger_ui_html = swagger_monkey_patch
from typing import Dict
user_api_base = None

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long