pythonasyncioapiasyncfastapiframeworkjsonjson-schemaopenapiopenapi3pydanticpython-typespython3redocreststarletteswaggerswagger-uiuvicornweb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
570 B
32 lines
570 B
from typing import 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
|
|
|