fix: dtos示例文件增加说明
This commit is contained in:
parent
6742916119
commit
cc6faebddc
|
|
@ -1,26 +1,25 @@
|
|||
from typing import List
|
||||
from typing import List, Optional
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from src.dtos import BaseModel, BaseResponse, ListResponse, PageItemModel
|
||||
|
||||
|
||||
class UserDto(BaseModel):
|
||||
id: int = Field(None, alias='id', description='id')
|
||||
userName: str = Field(None, description='用户名')
|
||||
class UserExampleDto(BaseModel):
|
||||
"""用户示例类"""
|
||||
id: int # 表示字段必需
|
||||
# Field 第一个参数:...代表字段必需 None代表字段可选,alias:表示返回最终的字段名,description: 文档描述
|
||||
userName: str = Field(..., alias="user_name", description='用户名')
|
||||
email: str = Field(None, description="用户email")
|
||||
age: Optional[int] # Optional 代表字段可选
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
allow_population_by_field_name = True
|
||||
class UserExampleListPagesItem(PageItemModel):
|
||||
items: List[UserExampleDto]
|
||||
|
||||
|
||||
class UserListPagesItem(PageItemModel):
|
||||
items: List[UserDto]
|
||||
class UserExampleListPagesResult(ListResponse):
|
||||
result: UserExampleListPagesItem
|
||||
|
||||
|
||||
class UserListPagesResult(ListResponse):
|
||||
result: UserListPagesItem
|
||||
|
||||
|
||||
class UserListResult(BaseResponse):
|
||||
result: List[UserDto]
|
||||
class UserExampleListResult(BaseResponse):
|
||||
result: List[UserExampleDto]
|
||||
Loading…
Reference in New Issue