mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-25 07:08:11 -05:00
* 📝 Add docs recommending Union over Optional * 📝 Update docs recommending Union over Optional * 📝 Update source examples for docs, recommend Union over Optional * 📝 Update highlighted lines with updated source examples * 📝 Update highlighted lines in Markdown with recent code changes * 📝 Update docs, use Union instead of Optional * ♻️ Update source examples to recommend Union over Optional * 🎨 Update highlighted code in Markdown after moving from Optional to Union
22 lines
442 B
Python
22 lines
442 B
Python
from typing import Union
|
|
|
|
from fastapi import Depends, FastAPI
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
async def common_parameters(
|
|
q: Union[str, None] = None, skip: int = 0, limit: int = 100
|
|
):
|
|
return {"q": q, "skip": skip, "limit": limit}
|
|
|
|
|
|
@app.get("/items/")
|
|
async def read_items(commons: dict = Depends(common_parameters)):
|
|
return commons
|
|
|
|
|
|
@app.get("/users/")
|
|
async def read_users(commons: dict = Depends(common_parameters)):
|
|
return commons
|