跳转至

模型配置

The BaseModel in Pydantic supports some custom configurations(Model Config),

by_alias⚓︎

Sometimes you may not want to use aliases (such as in the responses model). In that case, by_alias will be convenient:

1
2
3
4
5
6
7
class MessageResponse(BaseModel):
    message: str = Field(..., description="The message")
    metadata: dict[str, str] = Field(alias="metadata_")

    model_config = dict(
        by_alias=False
    )