11from dataclasses import dataclass , field
22from typing import Any , ClassVar , Dict , List , Optional
33
4+ from openapi_python_client import utils
5+
46from .reference import Reference
57
68
@@ -15,6 +17,11 @@ class Property:
1517 constructor_template : ClassVar [Optional [str ]] = None
1618 _type_string : ClassVar [str ]
1719
20+ python_name : str = field (init = False )
21+
22+ def __post_init__ (self ) -> None :
23+ self .python_name = utils .snake_case (self .name )
24+
1825 def get_type_string (self ) -> str :
1926 """ Get a string representation of type that should be used when declaring this property """
2027 if self .required :
@@ -31,13 +38,13 @@ def to_string(self) -> str:
3138 default = None
3239
3340 if default is not None :
34- return f"{ self .name } : { self .get_type_string ()} = { self .default } "
41+ return f"{ self .python_name } : { self .get_type_string ()} = { self .default } "
3542 else :
36- return f"{ self .name } : { self .get_type_string ()} "
43+ return f"{ self .python_name } : { self .get_type_string ()} "
3744
3845 def transform (self ) -> str :
3946 """ What it takes to turn this object into a native python type """
40- return self .name
47+ return self .python_name
4148
4249 def constructor_from_dict (self , dict_name : str ) -> str :
4350 """ How to load this property from a dict (used in generated model from_dict function """
@@ -57,6 +64,7 @@ class StringProperty(Property):
5764 _type_string : ClassVar [str ] = "str"
5865
5966 def __post_init__ (self ) -> None :
67+ super ().__post_init__ ()
6068 if self .default is not None :
6169 self .default = f'"{ self .default } "'
6270
@@ -146,6 +154,7 @@ class EnumListProperty(Property):
146154 constructor_template : ClassVar [str ] = "enum_list_property.pyi"
147155
148156 def __post_init__ (self ) -> None :
157+ super ().__post_init__ ()
149158 self .reference = Reference .from_ref (self .name )
150159
151160 def get_type_string (self ) -> str :
@@ -163,6 +172,7 @@ class EnumProperty(Property):
163172 reference : Reference = field (init = False )
164173
165174 def __post_init__ (self ) -> None :
175+ super ().__post_init__ ()
166176 self .reference = Reference .from_ref (self .name )
167177 inverse_values = {v : k for k , v in self .values .items ()}
168178 if self .default is not None :
@@ -177,7 +187,7 @@ def get_type_string(self) -> str:
177187
178188 def transform (self ) -> str :
179189 """ Output to the template, convert this Enum into a JSONable value """
180- return f"{ self .name } .value"
190+ return f"{ self .python_name } .value"
181191
182192 def constructor_from_dict (self , dict_name : str ) -> str :
183193 """ How to load this property from a dict (used in generated model from_dict function """
@@ -218,7 +228,7 @@ def get_type_string(self) -> str:
218228
219229 def transform (self ) -> str :
220230 """ Convert this into a JSONable value """
221- return f"{ self .name } .to_dict()"
231+ return f"{ self .python_name } .to_dict()"
222232
223233
224234@dataclass
0 commit comments