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.
30 lines
520 B
30 lines
520 B
from fastapi import FastAPI
|
|
from pydantic import BaseModel, HttpUrl
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
class Image(BaseModel):
|
|
url: HttpUrl
|
|
name: str
|
|
|
|
|
|
class Item(BaseModel):
|
|
name: str
|
|
description: str | None = None
|
|
price: float
|
|
tax: float | None = None
|
|
tags: set[str] = set()
|
|
images: list[Image] | None = None
|
|
|
|
|
|
class Offer(BaseModel):
|
|
name: str
|
|
description: str | None = None
|
|
price: float
|
|
items: list[Item]
|
|
|
|
|
|
@app.post("/offers/")
|
|
async def create_offer(offer: Offer):
|
|
return offer
|
|
|