Fix addProp and flatening
This commit is contained in:
Родитель
ca27867f44
Коммит
612a5d56d8
|
@ -1022,7 +1022,8 @@ class Deserializer(object):
|
|||
if "additional_properties" in attribute_map and attribute_map.get("additional_properties", {}).get("key") != '':
|
||||
# Check empty string. If it's not empty, someone has a real "additionalProperties"
|
||||
return None
|
||||
known_json_keys = {desc['key'] for desc in attribute_map.values() if desc['key'] != ''}
|
||||
known_json_keys = {_decode_attribute_map_key(_FLATTEN.split(desc['key'])[0])
|
||||
for desc in attribute_map.values() if desc['key'] != ''}
|
||||
present_json_keys = set(data.keys())
|
||||
missing_keys = present_json_keys - known_json_keys
|
||||
return {key: data[key] for key in missing_keys}
|
||||
|
|
|
@ -2076,6 +2076,36 @@ class TestRuntimeDeserialized(unittest.TestCase):
|
|||
self.assertEquals(m.additional_properties['PropArray'], [1,2,3])
|
||||
self.assertEquals(m.additional_properties['PropDict'], {"a": "b"})
|
||||
|
||||
def test_additional_properties_flattening(self):
|
||||
|
||||
class AdditionalTest(Model):
|
||||
|
||||
_attribute_map = {
|
||||
"name": {"key":"Name", "type":"str"},
|
||||
"content" :{"key":"Properties.Content", "type":"str"}
|
||||
}
|
||||
|
||||
def __init__(self, name=None, content=None):
|
||||
super(AdditionalTest, self).__init__()
|
||||
self.name = name
|
||||
self.content = content
|
||||
|
||||
message = {
|
||||
"Name": "test",
|
||||
"Properties": {
|
||||
"Content": "Content",
|
||||
"Unknown": "Unknown"
|
||||
}
|
||||
}
|
||||
|
||||
d = Deserializer({'AdditionalTest': AdditionalTest})
|
||||
|
||||
m = d('AdditionalTest', message)
|
||||
|
||||
self.assertEquals(m.name, "test")
|
||||
self.assertEquals(m.content, "Content")
|
||||
self.assertEquals(m.additional_properties, {})
|
||||
|
||||
|
||||
class TestModelInstanceEquality(unittest.TestCase):
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче