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
@@ -132,6 +140,7 @@ class EnumListProperty(Property):
132140 constructor_template : ClassVar [str ] = "enum_list_property.pyi"
133141
134142 def __post_init__ (self ) -> None :
143+ super ().__post_init__ ()
135144 self .reference = Reference .from_ref (self .name )
136145
137146 def get_type_string (self ) -> str :
@@ -149,6 +158,7 @@ class EnumProperty(Property):
149158 reference : Reference = field (init = False )
150159
151160 def __post_init__ (self ) -> None :
161+ super ().__post_init__ ()
152162 self .reference = Reference .from_ref (self .name )
153163 inverse_values = {v : k for k , v in self .values .items ()}
154164 if self .default is not None :
@@ -163,7 +173,7 @@ def get_type_string(self) -> str:
163173
164174 def transform (self ) -> str :
165175 """ Output to the template, convert this Enum into a JSONable value """
166- return f"{ self .name } .value"
176+ return f"{ self .python_name } .value"
167177
168178 def constructor_from_dict (self , dict_name : str ) -> str :
169179 """ How to load this property from a dict (used in generated model from_dict function """
@@ -204,7 +214,7 @@ def get_type_string(self) -> str:
204214
205215 def transform (self ) -> str :
206216 """ Convert this into a JSONable value """
207- return f"{ self .name } .to_dict()"
217+ return f"{ self .python_name } .to_dict()"
208218
209219
210220@dataclass
0 commit comments