mirror of https://github.com/tiangolo/fastapi.git
33 lines
581 B
Python
33 lines
581 B
Python
from typing import List, Set, Union
|
|
|
|
from fastapi import FastAPI
|
|
from pydantic import BaseModel, HttpUrl
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
class Image(BaseModel):
|
|
url: HttpUrl
|
|
name: str
|
|
|
|
|
|
class Item(BaseModel):
|
|
name: str
|
|
description: Union[str, None] = None
|
|
price: float
|
|
tax: Union[float, None] = None
|
|
tags: Set[str] = set()
|
|
images: Union[List[Image], None] = None
|
|
|
|
|
|
class Offer(BaseModel):
|
|
name: str
|
|
description: Union[str, None] = None
|
|
price: float
|
|
items: List[Item]
|
|
|
|
|
|
@app.post("/offers/")
|
|
async def create_offer(offer: Offer):
|
|
return offer
|