forked from fastapi/fastapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add support for forbidding extra form fields with Pydantic models (f…
…astapi#12134) Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
- Loading branch information
Showing
14 changed files
with
1,360 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from fastapi import FastAPI, Form | ||
from pydantic import BaseModel | ||
|
||
app = FastAPI() | ||
|
||
|
||
class FormData(BaseModel): | ||
username: str | ||
password: str | ||
model_config = {"extra": "forbid"} | ||
|
||
|
||
@app.post("/login/") | ||
async def login(data: FormData = Form()): | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from fastapi import FastAPI, Form | ||
from pydantic import BaseModel | ||
from typing_extensions import Annotated | ||
|
||
app = FastAPI() | ||
|
||
|
||
class FormData(BaseModel): | ||
username: str | ||
password: str | ||
model_config = {"extra": "forbid"} | ||
|
||
|
||
@app.post("/login/") | ||
async def login(data: Annotated[FormData, Form()]): | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from typing import Annotated | ||
|
||
from fastapi import FastAPI, Form | ||
from pydantic import BaseModel | ||
|
||
app = FastAPI() | ||
|
||
|
||
class FormData(BaseModel): | ||
username: str | ||
password: str | ||
model_config = {"extra": "forbid"} | ||
|
||
|
||
@app.post("/login/") | ||
async def login(data: Annotated[FormData, Form()]): | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from fastapi import FastAPI, Form | ||
from pydantic import BaseModel | ||
|
||
app = FastAPI() | ||
|
||
|
||
class FormData(BaseModel): | ||
username: str | ||
password: str | ||
|
||
class Config: | ||
extra = "forbid" | ||
|
||
|
||
@app.post("/login/") | ||
async def login(data: FormData = Form()): | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from fastapi import FastAPI, Form | ||
from pydantic import BaseModel | ||
from typing_extensions import Annotated | ||
|
||
app = FastAPI() | ||
|
||
|
||
class FormData(BaseModel): | ||
username: str | ||
password: str | ||
|
||
class Config: | ||
extra = "forbid" | ||
|
||
|
||
@app.post("/login/") | ||
async def login(data: Annotated[FormData, Form()]): | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from typing import Annotated | ||
|
||
from fastapi import FastAPI, Form | ||
from pydantic import BaseModel | ||
|
||
app = FastAPI() | ||
|
||
|
||
class FormData(BaseModel): | ||
username: str | ||
password: str | ||
|
||
class Config: | ||
extra = "forbid" | ||
|
||
|
||
@app.post("/login/") | ||
async def login(data: Annotated[FormData, Form()]): | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.