fastapi 中自动生成的 openapi3 怎样设置二级目录
source link: https://www.v2ex.com/t/825566
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
请问下,fastapi 中自动生成的 openapi3 怎样设置二级目录,多级目录,目前只有一级目录
zachlhb 1 小时 37 分钟前 via iPhone
skyone123 1 小时 0 分钟前
嗯,对,你先提前定义个 Response 的 model ,然后就可以统一返回了,形如
from typing import Generic, TypeVar, Optional, Union
from pydantic import Field
from pydantic.generics import GenericModel
Data = TypeVar('Data')
class ResultResponse(GenericModel, Generic[Data]):
"""
自定义返回模型,使用 generic-models 定义自定义模型
https://pydantic-docs.helpmanual.io/usage/models/#generic-models
所有返回数据都用如下格式,方便前端统一处理
{
code: 200,
message: '请求成功',
data: None
}
"""
code: int = Field(default=200, description='返回码')
message: str = Field(default='请求成功', description='消息内容')
result: Optional[Data]
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK