[python] Fixes additional_properties_type for models (#8802)

* Fixes additionalProperties values for models, updates docs, adds tag test of it, fixes frit and gmfruit tests

* Moves this.setDisallowAdditionalPropertiesIfNotPresent higher

* Makes setting additional_properties_model_instances contingent on the presence of addprosp in schema, updates sample spec composed schemas to remove addprops False form two

* Fixes oneOf anyOf allOf instantiation logic

* Removes Address from Cat definition

* Adds required vars for apple and banana, removes required vars from composed schema init sig

* Updates composed schema vars to be set on self and all composed instances

* Removes get_unused_args, get_var_name_to_model_instances, and get_additional_properties_model_instances

* Fixes fruit + deserilization tests, creates ComposedSchemaWithPropsAndNoAddProps

* Fixes FruitReq tests

* Fixes GmFruit tests

* Fixes discard_unknown_keys tests

* Samples updated

* Removes additionalproperties False in Child

* Samples updated

* Improves handling of v2 and v3 specs for isFreeFormObject, v2 sample spec updated with link to bug

* Adds cli option disallowAdditionalPropertiesIfNotPresent to python

* Adds getAdditionalProperties method so the value for addProps will be correct

* Reverts file

* Reverts file

* Updates python doc

* Reverted anytype_3 definition

* Updates test_deserialize_lizard

* Updates test_deserialize_dict_str_dog

* Updates testDog

* Updates testChild

* Adds v2 python_composition sample

* Adds needed files for python testing

* Adds existing tests into the new python sample

* Fixes test_dog

* Removes addProps false form Dog

* Fixes testChild

* Updates how additionalProperties are set

* Fixes empty_map type

* Type generation fixed for v2 and v3 specs

* Refactors getTypeString, updates artifactids in pom.xml files

* Adds new python sample to CI testing I think

* Fixes artifactId collision, regenrates docs
This commit is contained in:
Justin Black
2021-03-31 08:48:12 -07:00
committed by GitHub
parent 3973d4c831
commit 6cc270633b
539 changed files with 32476 additions and 1617 deletions

View File

@@ -73,14 +73,6 @@ class TestChild(unittest.TestCase):
}
)
# setting a value that doesn't exist raises an exception
# with a key
with self.assertRaises(petstore_api.ApiAttributeError):
child['invalid_variable'] = 'some value'
# with setattr
with self.assertRaises(petstore_api.ApiAttributeError):
setattr(child, 'invalid_variable', 'some value')
# with hasattr
self.assertFalse(hasattr(child, 'invalid_variable'))
@@ -123,17 +115,26 @@ class TestChild(unittest.TestCase):
self.assertEqual(
child._var_name_to_model_instances,
{
'radio_waves': [child, parent_instance],
'tele_vision': [child, parent_instance],
'inter_net': [child, child_allof_instance]
'radio_waves': [child, child_allof_instance, parent_instance],
'tele_vision': [child, child_allof_instance, parent_instance],
'inter_net': [child, child_allof_instance, parent_instance]
}
)
# model._additional_properties_model_instances stores a list of
# models which have the property additional_properties_type != None
self.assertEqual(
child._additional_properties_model_instances, []
child._additional_properties_model_instances, [child]
)
# setting a value that doesn't exist works
# with a key
child['invalid_variable'] = 'a'
assert child.invalid_variable == 'a'
# with setattr
setattr(child, 'invalid_variable', 'b')
assert child.invalid_variable == 'b'
# if we modify one of the properties owned by multiple
# model_instances we get an exception when we try to access that
# property because the retrieved values are not all the same
@@ -141,13 +142,13 @@ class TestChild(unittest.TestCase):
with self.assertRaises(petstore_api.ApiValueError):
inter_net = child.inter_net
# including extra parameters raises an exception
with self.assertRaises(petstore_api.ApiValueError):
child = Child(
radio_waves=radio_waves,
tele_vision=tele_vision,
inter_net=inter_net,
unknown_property='some value')
# including extra parameters works
child = Child(
radio_waves=radio_waves,
tele_vision=tele_vision,
inter_net=inter_net,
unknown_property='some value')
assert child.unknown_property == 'some value'
if __name__ == '__main__':
unittest.main()