refactor: migrate tag list API query parameters to Pydantic (#31097)

Co-authored-by: fghpdf <fghpdf@users.noreply.github.com>
This commit is contained in:
Xiangxuan Qu
2026-01-16 18:49:52 +09:00
committed by GitHub
parent de610cbf39
commit 1a9fdd9a65

View File

@ -30,6 +30,11 @@ class TagBindingRemovePayload(BaseModel):
type: Literal["knowledge", "app"] | None = Field(default=None, description="Tag type") type: Literal["knowledge", "app"] | None = Field(default=None, description="Tag type")
class TagListQueryParam(BaseModel):
type: Literal["knowledge", "app", ""] = Field("", description="Tag type filter")
keyword: str | None = Field(None, description="Search keyword")
register_schema_models( register_schema_models(
console_ns, console_ns,
TagBasePayload, TagBasePayload,
@ -43,12 +48,15 @@ class TagListApi(Resource):
@setup_required @setup_required
@login_required @login_required
@account_initialization_required @account_initialization_required
@console_ns.doc(
params={"type": 'Tag type filter. Can be "knowledge" or "app".', "keyword": "Search keyword for tag name."}
)
@marshal_with(dataset_tag_fields) @marshal_with(dataset_tag_fields)
def get(self): def get(self):
_, current_tenant_id = current_account_with_tenant() _, current_tenant_id = current_account_with_tenant()
tag_type = request.args.get("type", type=str, default="") raw_args = request.args.to_dict()
keyword = request.args.get("keyword", default=None, type=str) param = TagListQueryParam.model_validate(raw_args)
tags = TagService.get_tags(tag_type, current_tenant_id, keyword) tags = TagService.get_tags(param.type, current_tenant_id, param.keyword)
return tags, 200 return tags, 200