import typing
from fastapi import FastAPI, Response
from fastapi.responses import JSONResponse
from pydantic import BaseModel
app = FastAPI()
'''
响应模型
swagger Example显示
'''
class BaseUser(BaseModel):
username: str
email : str
class UserIn(BaseUser):
password : str
re_password : str
class UserOut(BaseUser):
pass
@app.post("/register",response_model=UserOut)
def register(user : UserIn):
# 注册用户的操作
return user
@app.post("/demo",response_model=typing.Dict[str,str])
# 字段类型转换
def dmeo():
return {
"name":"Tom",
"age":18
}