Skip to content

response_model_by_alias not respected by swagger schema #1810

@Smosker

Description

@Smosker

Hello! I have schema/view like this:

@router.get(
    "/my-route/",
    response_model=OutSchema,
    response_model_by_alias=False,
)
async def test_route(name: str):
    return await MyModel.query.where(
        and_(
            MyModel.name == name,
        )
    ).gino.first_or_404()


class OutSchema(BaseModel):
    id: int
    type: str
    object_id: str = Field(..., alias='name')

    class Config:
        orm_mode = True

Description

When i accessing route above i receive response like {'id': 123, 'type': 'smth', 'object_id': 'some_name'} which is correct

but when i open swagger i see in example response

{
  "id": 0,
  "type": "string",
  "name": "string" # it should be object_id here instead of name
}

It look like fastapi issue because of response_model_by_alias usage

Environment

  • OS: Linux
  • FastAPI Version: 0.55.1
  • Python version: 3.7

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions