mirror of
https://github.com/langgenius/dify.git
synced 2026-05-22 01:48:39 +08:00
Collapse the openapi-namespace per-app reads into one canonical endpoint
GET /openapi/v1/apps/<id>/describe[?fields=info,parameters,input_schema]
returning a single AppDescribeResponse with all blocks Optional and a new
JSON-Schema input_schema block derived server-side from user_input_form +
app mode.
- AppDescribeQuery (Pydantic, extra=forbid) parses the ?fields allow-list;
unknown member -> 422.
- _input_schema.build_input_schema(app) derives Draft 2020-12 JSON Schema:
chat-family modes carry top-level query (string, minLength=1, required);
workflow / completion only carry inputs. AppUnavailableError -> empty
sentinel (EMPTY_INPUT_SCHEMA).
- Drop AppByIdApi (/apps/<id>) and AppParametersApi (/apps/<id>/parameters)
route classes; delete app_info.py module + app_info_payload helper.
- AppDescribeResponse.{info,parameters,input_schema} now Optional[None].
Lock-step deploy with difyctl Phase B (/describe consumer migration).
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
from controllers.openapi._models import MessageMetadata, UsageInfo
|
|
|
|
|
|
def test_usage_info_defaults_zero():
|
|
u = UsageInfo()
|
|
assert u.prompt_tokens == 0
|
|
assert u.completion_tokens == 0
|
|
assert u.total_tokens == 0
|
|
|
|
|
|
def test_message_metadata_accepts_partial():
|
|
m = MessageMetadata(usage=UsageInfo(total_tokens=10))
|
|
assert m.usage.total_tokens == 10
|
|
assert m.retriever_resources == []
|
|
|
|
|
|
def test_describe_response_all_blocks_optional() -> None:
|
|
from controllers.openapi._models import AppDescribeResponse
|
|
|
|
payload = AppDescribeResponse().model_dump(mode="json", exclude_none=False)
|
|
assert payload == {"info": None, "parameters": None, "input_schema": None}
|
|
|
|
|
|
def test_describe_response_input_schema_field() -> None:
|
|
from controllers.openapi._models import AppDescribeResponse
|
|
|
|
schema = {"$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object"}
|
|
payload = AppDescribeResponse(input_schema=schema).model_dump(mode="json", exclude_none=False)
|
|
assert payload["input_schema"] == schema
|
|
assert payload["info"] is None
|
|
assert payload["parameters"] is None
|