diff --git a/litestar/openapi/spec/schema.py b/litestar/openapi/spec/schema.py index da4947ebef..05ce870338 100644 --- a/litestar/openapi/spec/schema.py +++ b/litestar/openapi/spec/schema.py @@ -1,7 +1,7 @@ from __future__ import annotations from dataclasses import dataclass, field, fields, is_dataclass -from typing import TYPE_CHECKING, Any, Hashable, Mapping, Sequence +from typing import TYPE_CHECKING, Any, Hashable, Mapping, Sequence, cast from litestar.openapi.spec.base import BaseSchemaObject from litestar.utils.predicates import is_non_string_sequence @@ -649,10 +649,13 @@ def __hash__(self) -> int: @classmethod def field_aliases(cls) -> dict[str, str]: + if hasattr(cls, "_field_aliases"): + return cast("dict[str, str]", cls._field_aliases) retval = {} for field_def in fields(cls): if field_def.metadata is not None and (field_alias := field_def.metadata.get("alias")): retval[field_alias] = field_def.name + cls._field_aliases = retval return retval