update swagger
This commit is contained in:
63
app/main.py
63
app/main.py
@@ -56,7 +56,35 @@ app = FastAPI(
|
||||
title=app_config.title,
|
||||
description=app_config.description,
|
||||
version=app_config.version,
|
||||
lifespan=lifespan
|
||||
lifespan=lifespan,
|
||||
# Swagger/OpenAPI 配置
|
||||
docs_url="/docs", # Swagger UI 路径
|
||||
redoc_url="/redoc", # ReDoc 路径
|
||||
openapi_url="/openapi.json", # OpenAPI schema 路径
|
||||
openapi_tags=[
|
||||
{
|
||||
"name": "Daily News",
|
||||
"description": "每日热点新闻数据接口,支持 22+ 个平台(百度、微博、知乎、GitHub 等)"
|
||||
},
|
||||
{
|
||||
"name": "Website Meta",
|
||||
"description": "网站元数据提取工具,可获取指定 URL 的标题、描述、图标等信息"
|
||||
},
|
||||
{
|
||||
"name": "Analysis",
|
||||
"description": "新闻趋势分析和预测功能"
|
||||
},
|
||||
{
|
||||
"name": "Health",
|
||||
"description": "健康检查接口"
|
||||
}
|
||||
],
|
||||
openapi_extra={
|
||||
"externalDocs": {
|
||||
"description": "项目源码仓库",
|
||||
"url": "https://github.com/hot-news/hot_news-main"
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
# 添加CORS中间件
|
||||
@@ -83,8 +111,39 @@ app.include_router(web_tools.router, prefix="/api/v1/tools/website-meta", tags=[
|
||||
app.include_router(analysis.router, prefix="/api/v1/analysis", tags=["Analysis"])
|
||||
|
||||
# 健康检查端点
|
||||
@app.get("/health", tags=["Health"])
|
||||
@app.get(
|
||||
"/health",
|
||||
summary="健康检查",
|
||||
description="检查 API 服务运行状态,返回服务状态和版本号",
|
||||
response_description="返回服务健康状态信息",
|
||||
responses={
|
||||
200: {
|
||||
"description": "服务正常运行",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"example": {
|
||||
"status": "healthy",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
tags=["Health"]
|
||||
)
|
||||
async def health_check():
|
||||
"""
|
||||
**健康检查接口**
|
||||
|
||||
用于监控服务运行状态,可用于:
|
||||
- 负载均衡器健康检查
|
||||
- 容器编排平台存活探测
|
||||
- 监控系统状态检测
|
||||
|
||||
**返回字段:**
|
||||
- `status`: 服务状态(healthy/unhealthy)
|
||||
- `version`: 当前服务版本
|
||||
"""
|
||||
return {"status": "healthy", "version": app_config.version}
|
||||
|
||||
# 如果直接运行此文件
|
||||
|
||||
Reference in New Issue
Block a user