swagger ui 国内链接

fastapi swagger


app.include_router(api_router)

# Add documentation endpoints only in test environment
if DEPLOY_API_ENVIROMENT == "test":
    logger.info("Test environment detected - Full documentation enabled with authentication")
    
    # Custom protected docs endpoints for TEST environment
    @app.get("/v1/doc/api-docs", include_in_schema=False)
    async def get_swagger_ui_documentation(
        request: Request,
        username: str = Depends(get_current_user)
    ):
        return get_swagger_ui_html(
            openapi_url="/v1/doc/openapi.json",
            title=app.title + " - Swagger UI (Test Environment)",
            swagger_js_url="https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/swagger-ui/5.9.0/swagger-ui-bundle.min.js",
            swagger_css_url="https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/swagger-ui/5.9.0/swagger-ui.min.css",
        )

    @app.get("/v1/doc/api-redoc", include_in_schema=False)
    async def get_redoc_documentation(
        request: Request,
        username: str = Depends(get_current_user)
    ):
        return get_redoc_html(
            openapi_url="/v1/doc/openapi.json",
            title=app.title + " - ReDoc (Test Environment)",
            redoc_js_url="https://s4.zstatic.net/npm/redoc@2.1.3/bundles/redoc.standalone.js",
        )

    @app.get("/v1/doc/openapi.json", include_in_schema=False)
    async def get_openapi_json(
        request: Request,
        username: str = Depends(get_current_user)
    ):
        from fastapi.openapi.utils import get_openapi
        return get_openapi(
            title=app.title,
            version=app.version,
            description=app.description,
            routes=app.routes,
        )

else:
    logger.info("Production environment detected - All documentation disabled")

ref: https://developer.aliyun.com/article/1426614
htps://fonts.font.im/css?family=Montserrat:300,400,700
https://blog.csdn.net/h1773655323/article/details/142098108

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值