refactor(web): API 路由统一 /api 前缀 + 完善 OpenAPI 文档
- 路由挂 APIRouter(prefix="/api"),健康检查路径 /health -> /api/health, 后期加接口(/api/compare、/api/queue 等)自动共享前缀。 - 文档路径归到 /api 下:/api/docs、/api/redoc、/api/openapi.json (原 /docs、/redoc、/openapi.json 已 404)。 - 新增 Pydantic 响应模型 schemas.py,并在 /api/health 挂 response_model, 使 /api/docs 展示完整响应结构。 - 为接口和每个响应字段补详细英文 description(覆盖范围、status 三态判定、 HTTP 码含义、各字段语义如 cycle_lag 阈值/dead 含义等)。 不动业务逻辑与同步主循环,仅 Web 层。
This commit is contained in:
@@ -143,7 +143,7 @@ def test_health_endpoint_returns_200_when_healthy():
|
||||
return_value={"available": False}):
|
||||
app = create_app(state, cfg)
|
||||
client = TestClient(app)
|
||||
r = client.get("/health")
|
||||
r = client.get("/api/health")
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["status"] == "healthy"
|
||||
@@ -162,7 +162,7 @@ def test_health_endpoint_returns_503_when_unhealthy():
|
||||
return_value={"available": False}):
|
||||
app = create_app(state, cfg)
|
||||
client = TestClient(app)
|
||||
r = client.get("/health")
|
||||
r = client.get("/api/health")
|
||||
assert r.status_code == 503
|
||||
assert r.json()["status"] == "unhealthy"
|
||||
|
||||
@@ -178,6 +178,6 @@ def test_health_endpoint_returns_503_when_degraded():
|
||||
return_value={"available": False}):
|
||||
app = create_app(state, cfg)
|
||||
client = TestClient(app)
|
||||
r = client.get("/health")
|
||||
r = client.get("/api/health")
|
||||
assert r.status_code == 503
|
||||
assert r.json()["status"] == "degraded"
|
||||
|
||||
Reference in New Issue
Block a user