docs_src/separate_openapi_schemas/tutorial001_py310.py
raw| 1 | from fastapi import FastAPI |
| 2 | from pydantic import BaseModel |
| 3 | |
| 4 | |
| 5 | class Item(BaseModel): |
| 6 | name: str |
| 7 | description: str | None = None |
| 8 | |
| 9 | |
| 10 | app = FastAPI() |
| 11 | |
| 12 | |
| 13 | @app.post("/items/") |
| 14 | def create_item(item: Item): |
| 15 | return item |
| 16 | |
| 17 | |
| 18 | @app.get("/items/") |
| 19 | def read_items() -> list[Item]: |
| 20 | return [ |
| 21 | Item( |
| 22 | name="Portal Gun", |
| 23 | description="Device to travel through the multi-rick-verse", |
| 24 | ), |
| 25 | Item(name="Plumbus"), |
| 26 | ] |