mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-23 22:29:34 -05:00
* 📝 Add docs for Separate OpenAPI Schemas for Input and Output * 🔧 Add new docs page to MkDocs config * ✨ Add separate_input_output_schemas parameter to FastAPI class * 📝 Add source examples for separating OpenAPI schemas * ✅ Add tests for separated OpenAPI schemas * 📝 Add source examples for Python 3.10, 3.9, and 3.7+ * 📝 Update docs for Separate OpenAPI Schemas with new multi-version examples * ✅ Add and update tests for different Python versions * ✅ Add tests for corner cases with separate_input_output_schemas * 📝 Update tutorial to use Union instead of Optional * 🐛 Fix type annotations * 🐛 Fix correct import in test * 💄 Add CSS to simulate browser windows for screenshots * ➕ Add playwright as a dev dependency to automate generating screenshots * 🔨 Add Playwright scripts to generate screenshots for new docs * 📝 Update docs, tweak text to match screenshots * 🍱 Add screenshots for new docs
29 lines
483 B
Python
29 lines
483 B
Python
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"),
|
|
]
|