如何在FastApi中创建基本模型
我正在研究Pydantic Basemodel。
我不知道如何编写基本模型以像示例示例一样获取API。
class ResponseModel(BaseModel):
code : int = Field(title="200")
message : str = Field(title="success")
data : object
custom_lasik : Optional[float] = Field(title="test")
custom_lasek : Optional[float] = Field(title="test")
lasik : Optional[float] = Field(title="test")
lasek : Optional[float] = Field(title="test")
smile_lasik : Optional[float] = Field(title="test")
toric : Optional[float] = Field(title="test")
normal : Optional[float] = Field(title="test")
class Config:
schema_extra = {
"example" : {
"code": 200,
"message": 'success',
"data": {
"custom_lasik" : 0.0,
"custom_lasek" : 0.0,
"lasik" : 0.5,
"lasek" : 0.35,
"smile_lasik" : 0.15,
"toric" : 0.0,
"normal" : 0.0
}
}
}
我认为DB的价值出现了,因为我连接了DB。
另外,我认为这是一个空的,因为我设置了可选的设置,但是我认为结果出现了两次,因为某个地方出了问题。
I'm working on a pydantic BaseModel.
I wonder how to write the BaseModel to get API called like the example example.
class ResponseModel(BaseModel):
code : int = Field(title="200")
message : str = Field(title="success")
data : object
custom_lasik : Optional[float] = Field(title="test")
custom_lasek : Optional[float] = Field(title="test")
lasik : Optional[float] = Field(title="test")
lasek : Optional[float] = Field(title="test")
smile_lasik : Optional[float] = Field(title="test")
toric : Optional[float] = Field(title="test")
normal : Optional[float] = Field(title="test")
class Config:
schema_extra = {
"example" : {
"code": 200,
"message": 'success',
"data": {
"custom_lasik" : 0.0,
"custom_lasek" : 0.0,
"lasik" : 0.5,
"lasek" : 0.35,
"smile_lasik" : 0.15,
"toric" : 0.0,
"normal" : 0.0
}
}
}
I think the value of db comes out because I connected db.
Also, I think there is a null because I set the Optional, but I am thinking that the result is coming out twice because something went wrong somewhere.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了答案并关闭问题
I found the answer and close the question