|
4 | 4 | self.__dict__[name] = value
|
5 | 5 | return
|
6 | 6 |
|
7 |
| - # set the attribute on the correct instance |
8 |
| - model_instances = self._var_name_to_model_instances.get( |
9 |
| - name, self._additional_properties_model_instances) |
10 |
| - if model_instances: |
11 |
| - for model_instance in model_instances: |
12 |
| - if model_instance == self: |
13 |
| - self.set_attribute(name, value) |
14 |
| - else: |
15 |
| - setattr(model_instance, name, value) |
16 |
| - if name not in self._var_name_to_model_instances: |
17 |
| - # we assigned an additional property |
18 |
| - self.__dict__['_var_name_to_model_instances'][name] = ( |
19 |
| - model_instance |
20 |
| - ) |
21 |
| - return None |
| 7 | + """ |
| 8 | + Use cases: |
| 9 | + 1. additional_properties_type is None (additionalProperties == False in spec) |
| 10 | + Check for property presence in self.openapi_types |
| 11 | + if not present then throw an error |
| 12 | + if present set in self, set attribute |
| 13 | + always set on composed schemas |
| 14 | + 2. additional_properties_type exists |
| 15 | + set attribute on self |
| 16 | + always set on composed schemas |
| 17 | + """ |
| 18 | + if self.additional_properties_type is None: |
| 19 | + """ |
| 20 | + For an attribute to exist on a composed schema it must: |
| 21 | + - fulfill schema_requirements in the self composed schema not considering oneOf/anyOf/allOf schemas AND |
| 22 | + - fulfill schema_requirements in each oneOf/anyOf/allOf schemas |
22 | 23 |
|
23 |
| - raise ApiAttributeError( |
24 |
| - "{0} has no attribute '{1}'".format( |
25 |
| - type(self).__name__, name), |
26 |
| - [e for e in [self._path_to_item, name] if e] |
27 |
| - ) |
| 24 | + schema_requirements: |
| 25 | + For an attribute to exist on a schema it must: |
| 26 | + - be present in properties at the schema OR |
| 27 | + - have additionalProperties unset (defaults additionalProperties = any type) OR |
| 28 | + - have additionalProperties set |
| 29 | + """ |
| 30 | + if name not in self.openapi_types: |
| 31 | + raise ApiAttributeError( |
| 32 | + "{0} has no attribute '{1}'".format( |
| 33 | + type(self).__name__, name), |
| 34 | + [e for e in [self._path_to_item, name] if e] |
| 35 | + ) |
| 36 | + # attribute must be set on self and composed instances |
| 37 | + self.set_attribute(name, value) |
| 38 | + for model_instance in self._composed_instances: |
| 39 | + setattr(model_instance, name, value) |
| 40 | + if name not in self._var_name_to_model_instances: |
| 41 | + # we assigned an additional property |
| 42 | + self.__dict__['_var_name_to_model_instances'][name] = self._composed_instances + [self] |
| 43 | + return None |
28 | 44 |
|
29 | 45 | __unset_attribute_value__ = object()
|
30 | 46 |
|
|
34 | 50 | return self.__dict__[name]
|
35 | 51 |
|
36 | 52 | # get the attribute from the correct instance
|
37 |
| - model_instances = self._var_name_to_model_instances.get( |
38 |
| - name, self._additional_properties_model_instances) |
| 53 | + model_instances = self._var_name_to_model_instances.get(name) |
39 | 54 | values = []
|
40 |
| - # A composed model stores child (oneof/anyOf/allOf) models under |
41 |
| - # self._var_name_to_model_instances. A named property can exist in |
42 |
| - # multiple child models. If the property is present in more than one |
43 |
| - # child model, the value must be the same across all the child models. |
| 55 | + # A composed model stores self and child (oneof/anyOf/allOf) models under |
| 56 | + # self._var_name_to_model_instances. |
| 57 | + # Any property must exist in self and all model instances |
| 58 | + # The value stored in all model instances must be the same |
44 | 59 | if model_instances:
|
45 | 60 | for model_instance in model_instances:
|
46 | 61 | if name in model_instance._data_store:
|
|
0 commit comments