14 lines
567 B
Python
14 lines
567 B
Python
![]() |
from typing import Optional, Any
|
|||
|
|
|||
|
from pydantic import BaseModel, Field
|
|||
|
|
|||
|
|
|||
|
class APIResponse(BaseModel):
|
|||
|
"""统一 API 响应模型(所有接口必返此格式)"""
|
|||
|
code: int = Field(..., description="状态码:200=成功、4xx=客户端错误、5xx=服务端错误")
|
|||
|
message: str = Field(..., description="响应信息:成功/错误描述")
|
|||
|
data: Optional[Any] = Field(None, description="响应数据:成功时返回、错误时为 None")
|
|||
|
|
|||
|
# Pydantic V2 配置(支持从 ORM 对象转换)
|
|||
|
model_config = {"from_attributes": True}
|