fastapi-master/docs_src/separate_openapi_schemas/tutorial001_py39.py

29 lines
483 B
Python
Raw Permalink Normal View History

2024-08-24 12:41:47 +08:00
from typing import Optional
from fastapi import FastAPI
from pydantic import BaseModel
class Item(BaseModel):
name: str
description: Optional[str] = None
app = FastAPI()
@app.post("/items/")
def create_item(item: Item):
return item
@app.get("/items/")
def read_items() -> list[Item]:
return [
Item(
name="Portal Gun",
description="Device to travel through the multi-rick-verse",
),
Item(name="Plumbus"),
]