2022-05-14 06:59:59 -05:00
|
|
|
from typing import Set, Union
|
2018-12-15 14:39:11 +04:00
|
|
|
|
2018-12-18 21:59:06 +04:00
|
|
|
from fastapi import FastAPI
|
2018-12-18 22:36:04 +04:00
|
|
|
from pydantic import BaseModel
|
2018-12-18 21:59:06 +04:00
|
|
|
|
2018-12-15 14:39:11 +04:00
|
|
|
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Item(BaseModel):
|
|
|
|
|
name: str
|
2022-05-14 06:59:59 -05:00
|
|
|
description: Union[str, None] = None
|
2018-12-15 14:39:11 +04: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()
|
2018-12-15 14:39:11 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.post(
|
|
|
|
|
"/items/",
|
|
|
|
|
response_model=Item,
|
|
|
|
|
summary="Create an item",
|
|
|
|
|
response_description="The created item",
|
|
|
|
|
)
|
2020-06-13 01:11:44 +05:30
|
|
|
async def create_item(item: Item):
|
2018-12-15 14:39:11 +04:00
|
|
|
"""
|
|
|
|
|
Create an item with all the information:
|
2019-04-16 22:49:18 +04:00
|
|
|
|
|
|
|
|
- **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
|
2018-12-15 14:39:11 +04:00
|
|
|
"""
|
|
|
|
|
return item
|