24 lines
638 B
Python
24 lines
638 B
Python
"""输入协议的公共类型"""
|
|
|
|
from typing import Annotated
|
|
|
|
from pydantic import AfterValidator, BaseModel, ConfigDict, JsonValue
|
|
|
|
|
|
def require_non_blank(value: str) -> str:
|
|
if not value.strip():
|
|
raise ValueError("不能为空或仅包含空白字符")
|
|
return value
|
|
|
|
|
|
NonBlankString = Annotated[str, AfterValidator(require_non_blank)]
|
|
JsonObject = dict[str, JsonValue]
|
|
|
|
|
|
class ExtensibleModel(BaseModel):
|
|
"""校验已知字段,保留未知 JSON 字段;不隐式转换输入类型"""
|
|
|
|
model_config = ConfigDict(extra="allow", strict=True, allow_inf_nan=False)
|
|
|
|
__pydantic_extra__: dict[str, JsonValue]
|