File tree Expand file tree Collapse file tree
src/datamodel_code_generator Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -856,7 +856,7 @@ def _get_preserved_type_origins() -> dict[type, str]:
856856 return _PRESERVED_TYPE_ORIGINS
857857
858858
859- def _serialize_python_type (tp : type ) -> str | None :
859+ def _serialize_python_type (tp : type ) -> str | None : # noqa: PLR0911
860860 """Serialize Python type to a string for x-python-type field.
861861
862862 Returns None if the type doesn't need to be preserved (e.g., standard dict, list).
@@ -884,6 +884,14 @@ def _serialize_python_type(tp: type) -> str | None:
884884 return " | " .join (n or _simple_type_name (a ) for n , a in zip (nested , args , strict = False ))
885885 return None # pragma: no cover
886886
887+ # Handle Annotated types - extract the base type and ignore metadata
888+ from typing import Annotated # noqa: PLC0415
889+
890+ if origin is Annotated :
891+ if args :
892+ return _serialize_python_type (args [0 ]) or _simple_type_name (args [0 ])
893+ return None # pragma: no cover
894+
887895 type_name : str | None = None
888896 if origin is not None :
889897 type_name = preserved_origins .get (origin )
You can’t perform that action at this time.
0 commit comments