diff --git a/litestar/_openapi/datastructures.py b/litestar/_openapi/datastructures.py index 91761e7eff..2c85476d3c 100644 --- a/litestar/_openapi/datastructures.py +++ b/litestar/_openapi/datastructures.py @@ -136,8 +136,7 @@ def get_reference_for_field_definition(self, field: FieldDefinition) -> Referenc key = _get_normalized_schema_key(field) if key not in self._schema_key_map: return None - - if (existing_type := self._component_type_map[key]) != field: + if (existing_type := self._component_type_map[key]) != field and f"{field.raw!r}" != f"{existing_type.raw!r}": # TODO: This should check for strict equality, e.g. changes in type metadata # However, this is currently not possible to do without breaking things, as # we allow to define metadata on a type annotation in one place to be used diff --git a/litestar/dto/_backend.py b/litestar/dto/_backend.py index ba121e0f5c..01a05a5065 100644 --- a/litestar/dto/_backend.py +++ b/litestar/dto/_backend.py @@ -207,7 +207,7 @@ def create_transfer_model_type( Returns: A ``BackendT`` class. """ - struct_name = self._create_transfer_model_name(model_name) + struct_name = self.dto_factory.__schema_name__ or self._create_transfer_model_name(model_name) struct = _create_struct_for_field_definitions( model_name=struct_name, diff --git a/litestar/dto/base_dto.py b/litestar/dto/base_dto.py index 93498f3c99..aae6c99d1b 100644 --- a/litestar/dto/base_dto.py +++ b/litestar/dto/base_dto.py @@ -52,6 +52,7 @@ class AbstractDTO(Generic[T]): """If ``annotation`` is an iterable, this is the inner type, otherwise will be the same as ``annotation``.""" _dto_backends: ClassVar[dict[str, _BackendDict]] = {} + __schema_name__: ClassVar[None | str] = None def __init__(self, asgi_connection: ASGIConnection) -> None: """Create an AbstractDTOFactory type.