Add support for Pydantic models for parameters using Query, Cookie, Header (#12199)

This commit is contained in:
Sebastián Ramírez
2024-09-17 20:54:10 +02:00
committed by GitHub
parent 0903da78c9
commit 55035f440b
72 changed files with 3253 additions and 45 deletions

View File

@@ -0,0 +1,21 @@
from typing import List, Union
from fastapi import FastAPI, Header
from pydantic import BaseModel
app = FastAPI()
class CommonHeaders(BaseModel):
model_config = {"extra": "forbid"}
host: str
save_data: bool
if_modified_since: Union[str, None] = None
traceparent: Union[str, None] = None
x_tag: List[str] = []
@app.get("/items/")
async def read_items(headers: CommonHeaders = Header()):
return headers