From 402d783161cac132e3f7bee31ba761566cd3c28c Mon Sep 17 00:00:00 2001 From: MonkaS Date: Tue, 21 Apr 2026 10:52:47 +0300 Subject: [PATCH] Fix: Pass OpenAPI schema data to all property types --- openapi_python_client/parser/properties/__init__.py | 10 ++++++++++ openapi_python_client/parser/properties/any.py | 1 + openapi_python_client/parser/properties/boolean.py | 3 +++ openapi_python_client/parser/properties/const.py | 4 ++++ openapi_python_client/parser/properties/date.py | 4 ++++ openapi_python_client/parser/properties/datetime.py | 4 ++++ .../parser/properties/enum_property.py | 2 ++ openapi_python_client/parser/properties/file.py | 4 ++++ openapi_python_client/parser/properties/float.py | 3 +++ openapi_python_client/parser/properties/int.py | 3 +++ .../parser/properties/list_property.py | 2 ++ .../parser/properties/literal_enum_property.py | 2 ++ openapi_python_client/parser/properties/none.py | 3 +++ openapi_python_client/parser/properties/string.py | 3 +++ openapi_python_client/parser/properties/union.py | 2 ++ openapi_python_client/parser/properties/uuid.py | 3 +++ 16 files changed, 53 insertions(+) diff --git a/openapi_python_client/parser/properties/__init__.py b/openapi_python_client/parser/properties/__init__.py index ba81d27c6..3b52033eb 100644 --- a/openapi_python_client/parser/properties/__init__.py +++ b/openapi_python_client/parser/properties/__init__.py @@ -64,6 +64,7 @@ def _string_based_property( python_name=python_name, description=data.description, example=data.example, + data=data, ) if string_format == "date": return DateProperty.build( @@ -73,6 +74,7 @@ def _string_based_property( python_name=python_name, description=data.description, example=data.example, + data=data, ) if string_format == "binary": return FileProperty.build( @@ -82,6 +84,7 @@ def _string_based_property( python_name=python_name, description=data.description, example=data.example, + data=data, ) if string_format == "uuid": return UuidProperty.build( @@ -91,6 +94,7 @@ def _string_based_property( python_name=python_name, description=data.description, example=data.example, + data=data, ) return StringProperty.build( name=name, @@ -99,6 +103,7 @@ def _string_based_property( python_name=python_name, description=data.description, example=data.example, + data=data, ) @@ -193,6 +198,7 @@ def property_from_data( # noqa: PLR0911, PLR0912 python_name=utils.PythonIdentifier(value=name, prefix=config.field_prefix), description=data.description, example=data.example, + data=data, ), schemas, ) @@ -232,6 +238,7 @@ def property_from_data( # noqa: PLR0911, PLR0912 const=data.const, python_name=utils.PythonIdentifier(value=name, prefix=config.field_prefix), description=data.description, + data=data, ), schemas, ) @@ -249,6 +256,7 @@ def property_from_data( # noqa: PLR0911, PLR0912 python_name=utils.PythonIdentifier(value=name, prefix=config.field_prefix), description=data.description, example=data.example, + data=data, ), schemas, ) @@ -261,6 +269,7 @@ def property_from_data( # noqa: PLR0911, PLR0912 python_name=utils.PythonIdentifier(value=name, prefix=config.field_prefix), description=data.description, example=data.example, + data=data, ), schemas, ) @@ -273,6 +282,7 @@ def property_from_data( # noqa: PLR0911, PLR0912 python_name=utils.PythonIdentifier(value=name, prefix=config.field_prefix), description=data.description, example=data.example, + data=data, ), schemas, ) diff --git a/openapi_python_client/parser/properties/any.py b/openapi_python_client/parser/properties/any.py index 65fcf40c4..9f6bada4e 100644 --- a/openapi_python_client/parser/properties/any.py +++ b/openapi_python_client/parser/properties/any.py @@ -5,6 +5,7 @@ from attr import define from ...utils import PythonIdentifier +from ... import schema as oai from .protocol import PropertyProtocol, Value diff --git a/openapi_python_client/parser/properties/boolean.py b/openapi_python_client/parser/properties/boolean.py index 5fd4235d7..fc44178ef 100644 --- a/openapi_python_client/parser/properties/boolean.py +++ b/openapi_python_client/parser/properties/boolean.py @@ -20,6 +20,7 @@ class BooleanProperty(PropertyProtocol): python_name: PythonIdentifier description: str | None example: str | None + data: oai.Schema _type_string: ClassVar[str] = "bool" _json_type_string: ClassVar[str] = "bool" @@ -40,6 +41,7 @@ def build( python_name: PythonIdentifier, description: str | None, example: str | None, + data: oai.Schema, ) -> BooleanProperty | PropertyError: checked_default = cls.convert_value(default) if isinstance(checked_default, PropertyError): @@ -51,6 +53,7 @@ def build( python_name=python_name, description=description, example=example, + data=data, ) @classmethod diff --git a/openapi_python_client/parser/properties/const.py b/openapi_python_client/parser/properties/const.py index 216941eb8..df50926f7 100644 --- a/openapi_python_client/parser/properties/const.py +++ b/openapi_python_client/parser/properties/const.py @@ -5,6 +5,7 @@ from attr import define from ...utils import PythonIdentifier +from ... import schema as oai from ..errors import PropertyError from .protocol import PropertyProtocol, Value from .string import StringProperty @@ -21,6 +22,7 @@ class ConstProperty(PropertyProtocol): python_name: PythonIdentifier description: str | None example: None + data: oai.Schema template: ClassVar[str] = "const_property.py.jinja" @classmethod @@ -33,6 +35,7 @@ def build( python_name: PythonIdentifier, required: bool, description: str | None, + data: oai.Schema, ) -> ConstProperty | PropertyError: """ Create a `ConstProperty` the right way. @@ -55,6 +58,7 @@ def build( default=None, description=description, example=None, + data=data, ) converted_default = prop.convert_value(default) if isinstance(converted_default, PropertyError): diff --git a/openapi_python_client/parser/properties/date.py b/openapi_python_client/parser/properties/date.py index 7261698ea..71e96a2a3 100644 --- a/openapi_python_client/parser/properties/date.py +++ b/openapi_python_client/parser/properties/date.py @@ -6,6 +6,7 @@ from dateutil.parser import isoparse from ...utils import PythonIdentifier +from ... import schema as oai from ..errors import PropertyError from .protocol import PropertyProtocol, Value @@ -20,6 +21,7 @@ class DateProperty(PropertyProtocol): python_name: PythonIdentifier description: str | None example: str | None + data: oai.Schema _type_string: ClassVar[str] = "datetime.date" _json_type_string: ClassVar[str] = "str" @@ -34,6 +36,7 @@ def build( python_name: PythonIdentifier, description: str | None, example: str | None, + data: oai.Schema ) -> DateProperty | PropertyError: checked_default = cls.convert_value(default) if isinstance(checked_default, PropertyError): @@ -46,6 +49,7 @@ def build( python_name=python_name, description=description, example=example, + data=data, ) @classmethod diff --git a/openapi_python_client/parser/properties/datetime.py b/openapi_python_client/parser/properties/datetime.py index 5924d173c..81948f1c6 100644 --- a/openapi_python_client/parser/properties/datetime.py +++ b/openapi_python_client/parser/properties/datetime.py @@ -6,6 +6,7 @@ from dateutil.parser import isoparse from ...utils import PythonIdentifier +from ... import schema as oai from ..errors import PropertyError from .protocol import PropertyProtocol, Value @@ -22,6 +23,7 @@ class DateTimeProperty(PropertyProtocol): python_name: PythonIdentifier description: str | None example: str | None + data: oai.Schema _type_string: ClassVar[str] = "datetime.datetime" _json_type_string: ClassVar[str] = "str" @@ -36,6 +38,7 @@ def build( python_name: PythonIdentifier, description: str | None, example: str | None, + data: oai.Schema, ) -> DateTimeProperty | PropertyError: checked_default = cls.convert_value(default) if isinstance(checked_default, PropertyError): @@ -48,6 +51,7 @@ def build( python_name=python_name, description=description, example=example, + data=data, ) @classmethod diff --git a/openapi_python_client/parser/properties/enum_property.py b/openapi_python_client/parser/properties/enum_property.py index 9845da7f4..28bc3061c 100644 --- a/openapi_python_client/parser/properties/enum_property.py +++ b/openapi_python_client/parser/properties/enum_property.py @@ -29,6 +29,7 @@ class EnumProperty(PropertyProtocol): python_name: utils.PythonIdentifier description: str | None example: str | None + data: oai.Schema values: dict[str, ValueType] class_info: Class value_type: type[ValueType] @@ -142,6 +143,7 @@ def build( # noqa: PLR0911 python_name=utils.PythonIdentifier(value=name, prefix=config.field_prefix), description=data.description, example=data.example, + data=data, ) checked_default = prop.convert_value(data.default) if isinstance(checked_default, PropertyError): diff --git a/openapi_python_client/parser/properties/file.py b/openapi_python_client/parser/properties/file.py index 90bbf6aec..bd96b81d7 100644 --- a/openapi_python_client/parser/properties/file.py +++ b/openapi_python_client/parser/properties/file.py @@ -5,6 +5,7 @@ from attr import define from ...utils import PythonIdentifier +from ... import schema as oai from ..errors import PropertyError from .protocol import PropertyProtocol @@ -19,6 +20,7 @@ class FileProperty(PropertyProtocol): python_name: PythonIdentifier description: str | None example: str | None + data: oai.Schema _type_string: ClassVar[str] = "File" # Return type of File.to_tuple() @@ -34,6 +36,7 @@ def build( python_name: PythonIdentifier, description: str | None, example: str | None, + data: oai.Schema, ) -> FileProperty | PropertyError: default_or_err = cls.convert_value(default) if isinstance(default_or_err, PropertyError): @@ -46,6 +49,7 @@ def build( python_name=python_name, description=description, example=example, + data=data, ) @classmethod diff --git a/openapi_python_client/parser/properties/float.py b/openapi_python_client/parser/properties/float.py index a785db6d4..ba0eba33f 100644 --- a/openapi_python_client/parser/properties/float.py +++ b/openapi_python_client/parser/properties/float.py @@ -20,6 +20,7 @@ class FloatProperty(PropertyProtocol): python_name: PythonIdentifier description: str | None example: str | None + data: oai.Schema _type_string: ClassVar[str] = "float" _json_type_string: ClassVar[str] = "float" @@ -40,6 +41,7 @@ def build( python_name: PythonIdentifier, description: str | None, example: str | None, + data: oai.Schema, ) -> FloatProperty | PropertyError: checked_default = cls.convert_value(default) if isinstance(checked_default, PropertyError): @@ -52,6 +54,7 @@ def build( python_name=python_name, description=description, example=example, + data=data, ) @classmethod diff --git a/openapi_python_client/parser/properties/int.py b/openapi_python_client/parser/properties/int.py index 1cd340fbd..57c0e8077 100644 --- a/openapi_python_client/parser/properties/int.py +++ b/openapi_python_client/parser/properties/int.py @@ -20,6 +20,7 @@ class IntProperty(PropertyProtocol): python_name: PythonIdentifier description: str | None example: str | None + data: oai.Schema _type_string: ClassVar[str] = "int" _json_type_string: ClassVar[str] = "int" @@ -40,6 +41,7 @@ def build( python_name: PythonIdentifier, description: str | None, example: str | None, + data: oai.Schema, ) -> IntProperty | PropertyError: checked_default = cls.convert_value(default) if isinstance(checked_default, PropertyError): @@ -52,6 +54,7 @@ def build( python_name=python_name, description=description, example=example, + data=data, ) @classmethod diff --git a/openapi_python_client/parser/properties/list_property.py b/openapi_python_client/parser/properties/list_property.py index 26ab0fdab..77b6b4154 100644 --- a/openapi_python_client/parser/properties/list_property.py +++ b/openapi_python_client/parser/properties/list_property.py @@ -21,6 +21,7 @@ class ListProperty(PropertyProtocol): python_name: utils.PythonIdentifier description: str | None example: str | None + data: oai.Schema inner_property: PropertyProtocol template: ClassVar[str] = "list_property.py.jinja" @@ -98,6 +99,7 @@ def build( python_name=utils.PythonIdentifier(value=name, prefix=config.field_prefix), description=data.description, example=data.example, + data=data, ), schemas, ) diff --git a/openapi_python_client/parser/properties/literal_enum_property.py b/openapi_python_client/parser/properties/literal_enum_property.py index f0e0306a2..ac7dd466c 100644 --- a/openapi_python_client/parser/properties/literal_enum_property.py +++ b/openapi_python_client/parser/properties/literal_enum_property.py @@ -29,6 +29,7 @@ class LiteralEnumProperty(PropertyProtocol): python_name: utils.PythonIdentifier description: str | None example: str | None + data: oai.Schema values: set[ValueType] class_info: Class value_type: type[ValueType] @@ -140,6 +141,7 @@ def build( # noqa: PLR0911 python_name=utils.PythonIdentifier(value=name, prefix=config.field_prefix), description=data.description, example=data.example, + data=data, ) checked_default = prop.convert_value(data.default) if isinstance(checked_default, PropertyError): diff --git a/openapi_python_client/parser/properties/none.py b/openapi_python_client/parser/properties/none.py index 9c473693d..7023e3acd 100644 --- a/openapi_python_client/parser/properties/none.py +++ b/openapi_python_client/parser/properties/none.py @@ -20,6 +20,7 @@ class NoneProperty(PropertyProtocol): python_name: PythonIdentifier description: str | None example: str | None + data: oai.Schema _allowed_locations: ClassVar[set[oai.ParameterLocation]] = { oai.ParameterLocation.QUERY, @@ -38,6 +39,7 @@ def build( python_name: PythonIdentifier, description: str | None, example: str | None, + data: oai.Schema ) -> NoneProperty | PropertyError: checked_default = cls.convert_value(default) if isinstance(checked_default, PropertyError): @@ -49,6 +51,7 @@ def build( python_name=python_name, description=description, example=example, + data=data, ) @classmethod diff --git a/openapi_python_client/parser/properties/string.py b/openapi_python_client/parser/properties/string.py index e40c1eee6..8ac01d844 100644 --- a/openapi_python_client/parser/properties/string.py +++ b/openapi_python_client/parser/properties/string.py @@ -21,6 +21,7 @@ class StringProperty(PropertyProtocol): python_name: PythonIdentifier description: str | None example: str | None + data: oai.Schema _type_string: ClassVar[str] = "str" _json_type_string: ClassVar[str] = "str" _allowed_locations: ClassVar[set[oai.ParameterLocation]] = { @@ -39,6 +40,7 @@ def build( python_name: PythonIdentifier, description: str | None, example: str | None, + data: oai.Schema, ) -> StringProperty | PropertyError: checked_default = cls.convert_value(default) return cls( @@ -48,6 +50,7 @@ def build( python_name=python_name, description=description, example=example, + data=data, ) @classmethod diff --git a/openapi_python_client/parser/properties/union.py b/openapi_python_client/parser/properties/union.py index 3091c793b..f31f74894 100644 --- a/openapi_python_client/parser/properties/union.py +++ b/openapi_python_client/parser/properties/union.py @@ -24,6 +24,7 @@ class UnionProperty(PropertyProtocol): python_name: PythonIdentifier description: str | None example: str | None + data: oai.Schema inner_properties: list[PropertyProtocol] template: ClassVar[str] = "union_property.py.jinja" @@ -112,6 +113,7 @@ def flatten_union_properties(possibly_nested: list[PropertyProtocol]) -> Iterato python_name=PythonIdentifier(value=name, prefix=config.field_prefix), description=data.description, example=data.example, + data=data, ) default_or_error = prop.convert_value(data.default) if isinstance(default_or_error, PropertyError): diff --git a/openapi_python_client/parser/properties/uuid.py b/openapi_python_client/parser/properties/uuid.py index 86d7d6a0a..ff404dbb4 100644 --- a/openapi_python_client/parser/properties/uuid.py +++ b/openapi_python_client/parser/properties/uuid.py @@ -21,6 +21,7 @@ class UuidProperty(PropertyProtocol): python_name: PythonIdentifier description: str | None example: str | None + data: oai.Schema _type_string: ClassVar[str] = "UUID" _json_type_string: ClassVar[str] = "str" @@ -41,6 +42,7 @@ def build( python_name: PythonIdentifier, description: str | None, example: str | None, + data: oai.Schema, ) -> UuidProperty | PropertyError: checked_default = cls.convert_value(default) if isinstance(checked_default, PropertyError): @@ -53,6 +55,7 @@ def build( python_name=python_name, description=description, example=example, + data=data, ) @classmethod