Hello
How can I raise the error if input pydantic's model has extra parameters?
Right now all extra keys are just ignored.
Example:
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class UpdateModel(BaseModel):
name: str
@app.post("/items/")
async def update(item: UpdateModel):
# do smth
If I send {"name": "FOO", "id": "BAR"} the ID key will be ignored.
Is it any common way to make method to raise error in that case?
Thanks for your work.
I believe the following should cause this to raise errors:
class UpdateModel(BaseModel):
name: str
class Config:
extra = "forbid"
This should be documented in the pydantic docs.
Thank you! Missed this in docs.
Thanks for the help here @dmontagu ! :clap: :bow:
Thanks for reporting back and closing the issue @rappongy :+1:
Most helpful comment
I believe the following should cause this to raise errors:
This should be documented in the pydantic docs.