mirror of
https://github.com/langgenius/dify.git
synced 2026-05-10 05:56:31 +08:00
fix(openapi): tighten WorkflowRunResponse.mode + outputs default
- WorkflowRunResponse.mode: Literal["workflow"] (was str) — only one valid value, so Literal makes the contract explicit. - WorkflowRunData.outputs: Field(default_factory=dict) — matches the sibling metadata field's idiom; avoids the mutable-literal-default smell flagged in code review. - Extends test_response_models_dump_per_mode with an explicit assertion on the WorkflowRunResponse.mode echo + exercises CompletionMessageResponse (was imported-but-unused).
This commit is contained in:
parent
40ae39a3a3
commit
1fb7329327
@ -2,7 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
from typing import Any, Literal
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
@ -96,7 +96,7 @@ class WorkflowRunData(BaseModel):
|
||||
id: str
|
||||
workflow_id: str
|
||||
status: str
|
||||
outputs: dict[str, Any] = {}
|
||||
outputs: dict[str, Any] = Field(default_factory=dict)
|
||||
error: str | None = None
|
||||
elapsed_time: float | None = None
|
||||
total_tokens: int | None = None
|
||||
@ -108,5 +108,5 @@ class WorkflowRunData(BaseModel):
|
||||
class WorkflowRunResponse(BaseModel):
|
||||
workflow_run_id: str
|
||||
task_id: str
|
||||
mode: str = "workflow" # echoed for CLI per-mode rendering — see endpoints.md L154
|
||||
mode: Literal["workflow"] = "workflow" # echoed for CLI per-mode rendering — see endpoints.md L154
|
||||
data: WorkflowRunData
|
||||
|
||||
@ -116,3 +116,9 @@ def test_response_models_dump_per_mode():
|
||||
data=WorkflowRunData(id="r1", workflow_id="w1", status="succeeded"),
|
||||
)
|
||||
assert wf.model_dump(mode="json")["data"]["status"] == "succeeded"
|
||||
assert wf.model_dump(mode="json")["mode"] == "workflow"
|
||||
comp = CompletionMessageResponse(
|
||||
event="message", task_id="t2", id="m2", message_id="m2",
|
||||
mode="completion", answer="ok", created_at=0,
|
||||
)
|
||||
assert comp.model_dump(mode="json")["mode"] == "completion"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user