[FastAPI-14]pydantic多个请求体
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
'''
多个请求体
{
"user": {
"username": "string",
"password": "string"
},
"item": {
"name": "string",
"description": "string",
"price": 0,
"tax": 0
}
}
'''
class User(BaseModel):
username: str
password: str
class Item(BaseModel):
name: str
description: str
price: float
tax: float
@app.post("/login")
def login(user: User, item: Item):
return {"user":user,
"item":item}