2022-05-14 06:59:59 -05:00
|
|
|
from typing import Union
|
2022-01-07 15:11:31 +01:00
|
|
|
|
|
|
|
|
from fastapi import FastAPI
|
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Item(BaseModel):
|
|
|
|
|
name: str
|
2022-05-14 06:59:59 -05:00
|
|
|
description: Union[str, None] = None
|
2022-01-07 15:11:31 +01:00
|
|
|
price: float
|
2022-05-14 06:59:59 -05:00
|
|
|
tax: Union[float, None] = None
|
2022-01-07 15:11:31 +01:00
|
|
|
tags: set[str] = set()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.post(
|
|
|
|
|
"/items/",
|
|
|
|
|
summary="Create an item",
|
|
|
|
|
response_description="The created item",
|
|
|
|
|
)
|
2026-02-04 15:07:26 +03:00
|
|
|
async def create_item(item: Item) -> Item:
|
2022-01-07 15:11:31 +01:00
|
|
|
"""
|
|
|
|
|
Create an item with all the information:
|
|
|
|
|
|
|
|
|
|
- **name**: each item must have a name
|
|
|
|
|
- **description**: a long description
|
|
|
|
|
- **price**: required
|
|
|
|
|
- **tax**: if the item doesn't have tax, you can omit this
|
|
|
|
|
- **tags**: a set of unique tag strings for this item
|
|
|
|
|
"""
|
|
|
|
|
return item
|