@@ -465,8 +465,9 @@ def _serialize(self, target_obj, data_type=None, **kwargs):
465465 if not keep_readonly and target_obj ._validation .get (attr_name , {}).get ('readonly' , False ):
466466 continue
467467
468- if attr_name == "additional_properties" and attr_desc ["key" ] == '' and target_obj .additional_properties :
469- serialized .update (target_obj .additional_properties )
468+ if attr_name == "additional_properties" and attr_desc ["key" ] == '' :
469+ if target_obj .additional_properties is not None :
470+ serialized .update (target_obj .additional_properties )
470471 continue
471472 try :
472473 ### Extract sub-data to serialize from model ###
@@ -548,6 +549,9 @@ def body(self, data, data_type, **kwargs):
548549 if internal_data_type and not isinstance (internal_data_type , Enum ):
549550 try :
550551 deserializer = Deserializer (self .dependencies )
552+ # Since it's on serialization, it's almost sure that format is not JSON REST
553+ # We're not able to deal with additional properties for now.
554+ deserializer .additional_properties_detection = False
551555 if issubclass (internal_data_type , Model ) and internal_data_type .is_xml_model ():
552556 deserializer .key_extractors = [
553557 attribute_key_case_insensitive_extractor ,
@@ -1196,6 +1200,13 @@ def __init__(self, classes=None):
11961200 rest_key_extractor ,
11971201 xml_key_extractor
11981202 ]
1203+ # Additional properties only works if the "rest_key_extractor" is used to
1204+ # extract the keys. Making it to work whatever the key extractor is too much
1205+ # complicated, with no real scenario for now.
1206+ # So adding a flag to disable additional properties detection. This flag should be
1207+ # used if your expect the deserialization to NOT come from a JSON REST syntax.
1208+ # Otherwise, result are unexpected
1209+ self .additional_properties_detection = True
11991210
12001211 def __call__ (self , target_obj , response_data , content_type = None ):
12011212 """Call the deserializer to process a REST response.
@@ -1279,10 +1290,12 @@ def _deserialize(self, target_obj, data):
12791290 msg = "Unable to deserialize to object: " + class_name
12801291 raise_with_traceback (DeserializationError , msg , err )
12811292 else :
1282- additional_properties = self ._build_additional_properties (response . _attribute_map , data )
1293+ additional_properties = self ._build_additional_properties (attributes , data )
12831294 return self ._instantiate_model (response , d_attrs , additional_properties )
12841295
12851296 def _build_additional_properties (self , attribute_map , data ):
1297+ if not self .additional_properties_detection :
1298+ return None
12861299 if "additional_properties" in attribute_map and attribute_map .get ("additional_properties" , {}).get ("key" ) != '' :
12871300 # Check empty string. If it's not empty, someone has a real "additionalProperties"
12881301 return None
0 commit comments