优化API文档,添加参数描述和示例

This commit is contained in:
2026-03-13 15:17:06 +08:00
parent 9a8d851275
commit b513d05611
38 changed files with 5846 additions and 1224 deletions
+20 -10
View File
@@ -1,4 +1,4 @@
from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException, Path, Query
from psycopg import AsyncConnection
import app.native.wndb as wndb
@@ -12,15 +12,18 @@ router = APIRouter()
async def get_database_connection(
conn: AsyncConnection = Depends(get_project_pg_connection),
):
"""获取数据库连接"""
yield conn
@router.get("/scada-info")
@router.get("/scada-info", summary="获取SCADA信息", description="使用连接池查询所有SCADA信息")
async def get_scada_info_with_connection(
conn: AsyncConnection = Depends(get_database_connection),
):
"""
使用连接池查询所有SCADA信息
获取所有SCADA信息
返回项目中所有的SCADA设备信息
"""
try:
_ = conn
@@ -33,12 +36,14 @@ async def get_scada_info_with_connection(
)
@router.get("/scheme-list")
@router.get("/scheme-list", summary="获取方案列表", description="使用连接池查询所有方案信息")
async def get_scheme_list_with_connection(
conn: AsyncConnection = Depends(get_database_connection),
):
"""
使用连接池查询所有方案信息
获取所有方案信息
返回项目中所有方案的详细信息
"""
try:
scheme_data = await SchemeRepository.get_schemes(conn)
@@ -47,12 +52,14 @@ async def get_scheme_list_with_connection(
raise HTTPException(status_code=500, detail=f"查询方案信息时发生错误: {str(e)}")
@router.get("/burst-locate-result")
@router.get("/burst-locate-result", summary="获取爆管定位结果", description="使用连接池查询所有爆管定位结果")
async def get_burst_locate_result_with_connection(
conn: AsyncConnection = Depends(get_database_connection),
):
"""
使用连接池查询所有爆管定位结果
获取所有爆管定位结果
返回项目中所有的爆管定位分析结果
"""
try:
burst_data = await SchemeRepository.get_burst_locate_results(conn)
@@ -63,13 +70,16 @@ async def get_burst_locate_result_with_connection(
)
@router.get("/burst-locate-result/{burst_incident}")
@router.get("/burst-locate-result/{burst_incident}", summary="按事件查询爆管定位结果", description="根据爆管事件ID查询对应的爆管定位结果")
async def get_burst_locate_result_by_incident(
burst_incident: str,
burst_incident: str = Path(..., description="爆管事件ID"),
conn: AsyncConnection = Depends(get_database_connection),
):
"""
根据 burst_incident 查询爆管定位结果
根据爆管事件ID查询爆管定位结果
参数:
burst_incident: 爆管事件的唯一标识符
"""
try:
return await SchemeRepository.get_burst_locate_result_by_incident(