swagger UI



redoc



swagger 加速

app = FastAPI(docs_url=None, redoc_url=None)  #这两个要为 None
#下载文件放到/static/下
    swagger-ui-bundle.js
    swagger-ui.css
    redoc.standalone.js
    css.css
    favicon.png

自定义挂载本地文件
OPENAPI_URL="/openapi.json"
SWAGGER_UI_OAUTH2_REDIRECT_URL="/docs/oauth2-redirect"
    @app.get("/docs", include_in_schema=False)
    async def custom_swagger_ui_html():
        return get_swagger_ui_html(
            # openapi_url=doc.openapi_url,
            openapi_url=OPENAPI_URL,
            title="Swagger UI",
            # oauth2_redirect_url=app.swagger_ui_oauth2_redirect_url,
            oauth2_redirect_url=SWAGGER_UI_OAUTH2_REDIRECT_URL,
            # swagger_js_url=BASE_DIR/'static'/'swagger-ui'/'swagger-ui-bundle.js',
            # swagger_css_url=BASE_DIR/'static'/'swagger-ui'/'swagger-ui.css',
            swagger_js_url="/static/swagger-ui-bundle.js",
            swagger_css_url="/static/swagger-ui.css",
            swagger_favicon_url="/static/favicon.png"
        )

    # doc.swagger_ui_oauth2_redirect_url,
    @app.get(SWAGGER_UI_OAUTH2_REDIRECT_URL, include_in_schema=False)
    async def swagger_ui_redirect():
        return get_swagger_ui_oauth2_redirect_html()

    @app.get("/redoc", include_in_schema=False)
    async def redoc_html():
        return get_redoc_html(
            # openapi_url=doc.openapi_url,
            openapi_url=OPENAPI_URL,
            title="ReDoc",
            redoc_js_url="/static/redoc.standalone.js",
            redoc_favicon_url="/static/favicon.png",
            with_google_fonts=False
        )