#5102·litestar

Bug: DTO nested models of the same type get colliding names, exposing module path in OpenAPI component names

Author: jeongeundevCreated Sep 29, 2026Updated Sep 29, 2026

Description

When a model has two fields of the same type (e.g. author: User, editor: User), the nested DTO model names collide and one of them gets the handler path in its OpenAPI name, like __main__.get_postPostUserResponseBody.

Could we include the field name in the generated name? It would change existing names, so I'd like to check before opening a PR.

MCVE

python
from dataclasses import dataclass

from litestar import Litestar, get
from litestar.dto import DataclassDTO


@dataclass
class User:
    id: int


@dataclass
class Post:
    author: User
    editor: User


@get("/", return_dto=DataclassDTO[Post])
async def get_post() -> Post:
    return Post(author=User(id=1), editor=User(id=2))


app = Litestar([get_post])
print(list(app.openapi_schema.to_schema()["components"]["schemas"]))
# ['GetPostPostResponseBody', 'GetPostPostUserResponseBody', '__main__.get_postPostUserResponseBody']

Litestar Version

main (3.0.0b0), 2.24.0