Skip to content

Commit 86d2479

Browse files
committed
update 1.1.5
1 parent cbc58c5 commit 86d2479

File tree

8 files changed

+135
-1800
lines changed

8 files changed

+135
-1800
lines changed

backend/app/core/init_app.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
from fastapi import FastAPI
4+
from fastapi import FastAPI, applications
55
from app.core.config import settings
66
from app.utils.tools import import_module
77
from app.core.exceptions import (
@@ -64,27 +64,28 @@ def register_routers(app: FastAPI, prefix: str = "/") -> None:
6464
app.include_router(ApiRouter, prefix=prefix)
6565

6666

67-
def reset_swagger(app: FastAPI) -> FastAPI:
67+
def reset_api_docs() -> None:
6868
"""
69-
修复API文档CDN无法访问的问题
69+
修复Redoc API文档CDN无法访问的问题
7070
"""
71-
@app.get("/docs", include_in_schema=False)
72-
async def custom_swagger_ui_html() -> HTMLResponse:
71+
72+
def swagger_monkey_patch(*args, **kwargs):
73+
"""
74+
修复Swagger API文档CDN无法访问的问题
75+
"""
7376
return get_swagger_ui_html(
74-
openapi_url=app.openapi_url,
75-
title=app.title,
77+
*args, **kwargs,
7678
swagger_css_url="/static/swagger/swagger-ui/swagger-ui.css",
7779
swagger_js_url="/static/swagger/swagger-ui/swagger-ui-bundle.js",
78-
swagger_favicon_url="/static/swagger/favicon.png",
80+
swagger_favicon_url="/static/swagger/favicon.png"
7981
)
8082

81-
@app.get("/redoc", include_in_schema=False)
82-
async def redoc_html() -> HTMLResponse:
83+
def redoc_monkey_patch(*args, **kwargs):
8384
return get_redoc_html(
84-
openapi_url=app.openapi_url,
85-
title=app.title + " - ReDoc",
85+
*args, **kwargs,
8686
redoc_js_url="/static/swagger/redoc/bundles/redoc.standalone.js",
87-
redoc_favicon_url="/static/swagger/favicon.png",
87+
redoc_favicon_url="/static/swagger/favicon.png"
8888
)
8989

90-
return app
90+
applications.get_swagger_ui_html = swagger_monkey_patch
91+
applications.get_redoc_html = redoc_monkey_patch

backend/app/static/swagger/redoc/bundles/redoc.standalone.js

Lines changed: 113 additions & 1781 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/app/static/swagger/redoc/bundles/redoc.standalone.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/app/static/swagger/swagger-ui/swagger-ui-bundle.js

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/app/static/swagger/swagger-ui/swagger-ui-bundle.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/app/static/swagger/swagger-ui/swagger-ui.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/app/static/swagger/swagger-ui/swagger-ui.css.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
register_middlewares,
1010
register_exceptions,
1111
register_routers,
12-
reset_swagger
12+
reset_api_docs
1313
)
1414
import uvicorn, typer
1515
from app.scripts.initialize import InitializeData
@@ -33,7 +33,7 @@ def create_app() -> FastAPI:
3333
# 注册中间件
3434
register_middlewares(app)
3535
# 重设API文档
36-
reset_swagger(app)
36+
reset_api_docs()
3737

3838
return app
3939

0 commit comments

Comments
 (0)