mirror of
https://github.com/fastapi/fastapi.git
synced 2026-04-05 07:34:12 -04:00
✨ Add support for disabling the separation of input and output JSON Schemas in OpenAPI with Pydantic v2 (#10145)
* 📝 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
This commit is contained in:
committed by
GitHub
parent
10a127ea4a
commit
ea43f227e5
28
docs_src/separate_openapi_schemas/tutorial001.py
Normal file
28
docs_src/separate_openapi_schemas/tutorial001.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from typing import List, Union
|
||||
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
name: str
|
||||
description: Union[str, None] = 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"),
|
||||
]
|
||||
26
docs_src/separate_openapi_schemas/tutorial001_py310.py
Normal file
26
docs_src/separate_openapi_schemas/tutorial001_py310.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
name: str
|
||||
description: str | None = 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"),
|
||||
]
|
||||
28
docs_src/separate_openapi_schemas/tutorial001_py39.py
Normal file
28
docs_src/separate_openapi_schemas/tutorial001_py39.py
Normal file
@@ -0,0 +1,28 @@
|
||||
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"),
|
||||
]
|
||||
28
docs_src/separate_openapi_schemas/tutorial002.py
Normal file
28
docs_src/separate_openapi_schemas/tutorial002.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from typing import List, Union
|
||||
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
name: str
|
||||
description: Union[str, None] = None
|
||||
|
||||
|
||||
app = FastAPI(separate_input_output_schemas=False)
|
||||
|
||||
|
||||
@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"),
|
||||
]
|
||||
26
docs_src/separate_openapi_schemas/tutorial002_py310.py
Normal file
26
docs_src/separate_openapi_schemas/tutorial002_py310.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
name: str
|
||||
description: str | None = None
|
||||
|
||||
|
||||
app = FastAPI(separate_input_output_schemas=False)
|
||||
|
||||
|
||||
@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"),
|
||||
]
|
||||
28
docs_src/separate_openapi_schemas/tutorial002_py39.py
Normal file
28
docs_src/separate_openapi_schemas/tutorial002_py39.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
|
||||
|
||||
app = FastAPI(separate_input_output_schemas=False)
|
||||
|
||||
|
||||
@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"),
|
||||
]
|
||||
Reference in New Issue
Block a user