-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Privileged issue
- I'm @tiangolo or he asked me directly to create an issue here.
Issue Content
The Body, File, and Form parameters don't support alias.
The following snippet demonstrates the issue:
from typing import Annotated
from fastapi import Body, Cookie, FastAPI, Form, UploadFile, File, Query, Header, Path
app = FastAPI()
@app.post("/{path}")
def endpoint(
path: Annotated[int, Path(alias="PathAlias")],
cookie: Annotated[int, Cookie(alias="CookieAlias")],
header: Annotated[int, Header(alias="HeaderAlias")],
query: Annotated[int, Query(alias="QueryAlias")],
body: Annotated[int, Body(alias="BodyAlias")],
form: Annotated[int, Form(alias="FormAlias")],
file: Annotated[UploadFile, File(alias="FileAlias")],
):
...If you look at the generated Swagger you see that alias is only being used for params.Param related fields i.e. Path, Cookie, etc.
People can overcome this right now using validation_alias as follows:
from typing import Annotated
from fastapi import Body, Cookie, FastAPI, Form, UploadFile, File, Query, Header, Path
app = FastAPI()
@app.post("/{path}")
def endpoint(
path: Annotated[int, Path(alias="PathAlias")],
cookie: Annotated[int, Cookie(alias="CookieAlias")],
header: Annotated[int, Header(alias="HeaderAlias")],
query: Annotated[int, Query(alias="QueryAlias")],
body: Annotated[int, Body(validation_alias="BodyAlias")],
form: Annotated[int, Form(validation_alias="FormAlias")],
file: Annotated[UploadFile, File(validation_alias="FileAlias")],
):
...In any case, this should be fixed in FastAPI.
balazser, alexwilson1, hard-coders, falkben, pberezow and 6 more
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working