✨ Add support for Pydantic models in Form parameters (#12129)

Revert "⏪️ Temporarily revert "✨ Add support for Pydantic models in `Form` pa…"

This reverts commit 8e6cf9ee9c.
This commit is contained in:
Sebastián Ramírez authored and GitHub committed 2024-09-05 17:16:50 +02:00
1 parent 965fc8301e
commit 7bad7c0975
13 files changed
+994 -3

No files matched your search

@@ -0,0 +1,14 @@
from fastapi import FastAPI, Form
from pydantic import BaseModel
app = FastAPI()
class FormData(BaseModel):
username: str
password: str
@app.post("/login/")
async def login(data: FormData = Form()):
return data
@@ -0,0 +1,15 @@
from fastapi import FastAPI, Form
from pydantic import BaseModel
from typing_extensions import Annotated
app = FastAPI()
class FormData(BaseModel):
username: str
password: str
@app.post("/login/")
async def login(data: Annotated[FormData, Form()]):
return data
@@ -0,0 +1,16 @@
from typing import Annotated
from fastapi import FastAPI, Form
from pydantic import BaseModel
app = FastAPI()
class FormData(BaseModel):
username: str
password: str
@app.post("/login/")
async def login(data: Annotated[FormData, Form()]):
return data