Pydantic models use the field alias for validation and the field name for serialization (unless prefer_alias=True
is passed explicitly). However the generated OpenAPI shows the alias for both request and response if the model is the same.
No response
from litestar import Litestar, post
from pydantic import BaseModel, Field
class User(BaseModel):
first_name: str = Field(alias="FirstName")
last_name: str = Field(alias="LastName")
@post()
async def test(data: User) -> User:
return data
app = Litestar(route_handlers=[test])
2.4.3
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too