docs(backend): SSE 端点在 OpenAPI 如实声明 text/event-stream
draft/rewrite/review 三个流式端点返回 StreamingResponse,OpenAPI 原按默认 application/json 标注 200,schema 不诚实。新增共享 _SSE_RESPONSE 声明 200 的 content 为 text/event-stream 并挂到三个装饰器。export_openapi 通过,schema 现 出现 3 处 text/event-stream。未跑前端 gen:api(按要求)。
This commit is contained in:
@@ -105,6 +105,13 @@ _ACCEPT_ERRORS: dict[int | str, dict[str, Any]] = {
|
||||
409: {"model": ErrorEnvelope, "description": "存在未裁决冲突"},
|
||||
503: {"model": ErrorEnvelope, "description": "LLM 不可用"},
|
||||
}
|
||||
# SSE 端点:如实声明 200 的 media type 为 text/event-stream(否则 OpenAPI 误标 json)。
|
||||
_SSE_RESPONSE: dict[int | str, dict[str, Any]] = {
|
||||
200: {
|
||||
"description": "SSE 事件流(`event: <name>\\ndata: <json>`,见 memory/contracts.md)",
|
||||
"content": {"text/event-stream": {}},
|
||||
}
|
||||
}
|
||||
|
||||
ProjectRepoDep = Annotated[ProjectRepo, Depends(get_project_repo)]
|
||||
ChapterRepoDep = Annotated[ChapterRepo, Depends(get_chapter_repo)]
|
||||
@@ -256,7 +263,7 @@ def _encode_sse(event: SseEvent) -> str:
|
||||
return f"event: {event.event}\ndata: {payload}\n\n"
|
||||
|
||||
|
||||
@router.post("/{project_id}/chapters/{chapter_no}/draft")
|
||||
@router.post("/{project_id}/chapters/{chapter_no}/draft", responses=_SSE_RESPONSE)
|
||||
async def stream_draft(
|
||||
project_id: uuid.UUID,
|
||||
chapter_no: int,
|
||||
@@ -319,7 +326,7 @@ async def stream_draft(
|
||||
)
|
||||
|
||||
|
||||
@router.post("/{project_id}/chapters/{chapter_no}/rewrite")
|
||||
@router.post("/{project_id}/chapters/{chapter_no}/rewrite", responses=_SSE_RESPONSE)
|
||||
async def stream_rewrite(
|
||||
project_id: uuid.UUID,
|
||||
chapter_no: int,
|
||||
@@ -532,7 +539,7 @@ async def _resolve_review_draft(
|
||||
return saved.content
|
||||
|
||||
|
||||
@router.post("/{project_id}/chapters/{chapter_no}/review")
|
||||
@router.post("/{project_id}/chapters/{chapter_no}/review", responses=_SSE_RESPONSE)
|
||||
async def review_chapter(
|
||||
project_id: uuid.UUID,
|
||||
chapter_no: int,
|
||||
|
||||
Reference in New Issue
Block a user