@@ -177,7 +177,6 @@ class UnionProperty(Property):
177177 has_properties_without_templates : bool = attr .ib (init = False )
178178
179179 def __attrs_post_init__ (self ) -> None :
180- super ().__attrs_post_init__ ()
181180 object .__setattr__ (
182181 self , "has_properties_without_templates" , any (prop .template is None for prop in self .inner_properties )
183182 )
@@ -235,30 +234,34 @@ def inner_properties_with_template(self) -> Iterator[Property]:
235234
236235
237236def _string_based_property (
238- name : str , required : bool , data : oai .Schema
237+ name : str , required : bool , data : oai .Schema , config : Config
239238) -> Union [StringProperty , DateProperty , DateTimeProperty , FileProperty ]:
240239 """Construct a Property from the type "string" """
241240 string_format = data .schema_format
241+ python_name = utils .PythonIdentifier (value = name , prefix = config .field_prefix )
242242 if string_format == "date-time" :
243243 return DateTimeProperty (
244244 name = name ,
245245 required = required ,
246246 default = convert ("datetime.datetime" , data .default ),
247247 nullable = data .nullable ,
248+ python_name = python_name ,
248249 )
249250 elif string_format == "date" :
250251 return DateProperty (
251252 name = name ,
252253 required = required ,
253254 default = convert ("datetime.date" , data .default ),
254255 nullable = data .nullable ,
256+ python_name = python_name ,
255257 )
256258 elif string_format == "binary" :
257259 return FileProperty (
258260 name = name ,
259261 required = required ,
260262 default = None ,
261263 nullable = data .nullable ,
264+ python_name = python_name ,
262265 )
263266 else :
264267 return StringProperty (
@@ -267,6 +270,7 @@ def _string_based_property(
267270 required = required ,
268271 pattern = data .pattern ,
269272 nullable = data .nullable ,
273+ python_name = python_name ,
270274 )
271275
272276
@@ -326,6 +330,7 @@ def build_enum_property(
326330 values = values ,
327331 value_type = value_type ,
328332 default = None ,
333+ python_name = utils .PythonIdentifier (value = name , prefix = config .field_prefix ),
329334 )
330335
331336 default = get_enum_default (prop , data )
@@ -373,6 +378,7 @@ def build_union_property(
373378 default = default ,
374379 inner_properties = sub_properties ,
375380 nullable = data .nullable ,
381+ python_name = utils .PythonIdentifier (value = name , prefix = config .field_prefix ),
376382 ),
377383 schemas ,
378384 )
@@ -395,6 +401,7 @@ def build_list_property(
395401 default = None ,
396402 inner_property = inner_prop ,
397403 nullable = data .nullable ,
404+ python_name = utils .PythonIdentifier (value = name , prefix = config .field_prefix ),
398405 ),
399406 schemas ,
400407 )
@@ -406,6 +413,7 @@ def _property_from_ref(
406413 parent : Union [oai .Schema , None ],
407414 data : oai .Reference ,
408415 schemas : Schemas ,
416+ config : Config ,
409417) -> Tuple [Union [Property , PropertyError ], Schemas ]:
410418 ref_path = parse_reference_path (data .ref )
411419 if isinstance (ref_path , ParseError ):
@@ -414,7 +422,12 @@ def _property_from_ref(
414422 if not existing :
415423 return PropertyError (data = data , detail = "Could not find reference in parsed models or enums" ), schemas
416424
417- prop = attr .evolve (existing , required = required , name = name )
425+ prop = attr .evolve (
426+ existing ,
427+ required = required ,
428+ name = name ,
429+ python_name = utils .PythonIdentifier (value = name , prefix = config .field_prefix ),
430+ )
418431 if parent :
419432 prop = attr .evolve (prop , nullable = parent .nullable )
420433 if isinstance (prop , EnumProperty ):
@@ -437,12 +450,14 @@ def _property_from_data(
437450 """Generate a Property from the OpenAPI dictionary representation of it"""
438451 name = utils .remove_string_escapes (name )
439452 if isinstance (data , oai .Reference ):
440- return _property_from_ref (name = name , required = required , parent = None , data = data , schemas = schemas )
453+ return _property_from_ref (name = name , required = required , parent = None , data = data , schemas = schemas , config = config )
441454
442455 # A union of a single reference should just be passed through to that reference (don't create copy class)
443456 sub_data = (data .allOf or []) + data .anyOf + data .oneOf
444457 if len (sub_data ) == 1 and isinstance (sub_data [0 ], oai .Reference ):
445- return _property_from_ref (name = name , required = required , parent = data , data = sub_data [0 ], schemas = schemas )
458+ return _property_from_ref (
459+ name = name , required = required , parent = data , data = sub_data [0 ], schemas = schemas , config = config
460+ )
446461
447462 if data .enum :
448463 return build_enum_property (
@@ -459,14 +474,15 @@ def _property_from_data(
459474 data = data , name = name , required = required , schemas = schemas , parent_name = parent_name , config = config
460475 )
461476 elif data .type == "string" :
462- return _string_based_property (name = name , required = required , data = data ), schemas
477+ return _string_based_property (name = name , required = required , data = data , config = config ), schemas
463478 elif data .type == "number" :
464479 return (
465480 FloatProperty (
466481 name = name ,
467482 default = convert ("float" , data .default ),
468483 required = required ,
469484 nullable = data .nullable ,
485+ python_name = utils .PythonIdentifier (value = name , prefix = config .field_prefix ),
470486 ),
471487 schemas ,
472488 )
@@ -477,6 +493,7 @@ def _property_from_data(
477493 default = convert ("int" , data .default ),
478494 required = required ,
479495 nullable = data .nullable ,
496+ python_name = utils .PythonIdentifier (value = name , prefix = config .field_prefix ),
480497 ),
481498 schemas ,
482499 )
@@ -487,6 +504,7 @@ def _property_from_data(
487504 required = required ,
488505 default = convert ("bool" , data .default ),
489506 nullable = data .nullable ,
507+ python_name = utils .PythonIdentifier (value = name , prefix = config .field_prefix ),
490508 ),
491509 schemas ,
492510 )
@@ -499,7 +517,16 @@ def _property_from_data(
499517 data = data , name = name , schemas = schemas , required = required , parent_name = parent_name , config = config
500518 )
501519 elif not data .type :
502- return AnyProperty (name = name , required = required , nullable = False , default = None ), schemas
520+ return (
521+ AnyProperty (
522+ name = name ,
523+ required = required ,
524+ nullable = False ,
525+ default = None ,
526+ python_name = utils .PythonIdentifier (value = name , prefix = config .field_prefix ),
527+ ),
528+ schemas ,
529+ )
503530 return PropertyError (data = data , detail = f"unknown type { data .type } " ), schemas
504531
505532
0 commit comments