@@ -172,6 +172,16 @@ def model_factory(self):
172
172
return ModelFactory ()
173
173
174
174
def unmarshal (self , value ):
175
+ properties = self .unmarshal_raw (value )
176
+
177
+ if 'x-model' in self .schema :
178
+ name = self .schema ['x-model' ]
179
+ model = self .model_factory .create (properties , name = name )
180
+ return model
181
+
182
+ return properties
183
+
184
+ def unmarshal_raw (self , value ):
175
185
try :
176
186
value = self .formatter .unmarshal (value )
177
187
except ValueError as exc :
@@ -180,48 +190,49 @@ def unmarshal(self, value):
180
190
else :
181
191
return self ._unmarshal_object (value )
182
192
193
+ def _clone (self , schema ):
194
+ return ObjectUnmarshaller (
195
+ schema , self .formatter , self .validator , self .unmarshallers_factory ,
196
+ self .context )
197
+
183
198
def _unmarshal_object (self , value ):
199
+ properties = {}
200
+
184
201
if 'oneOf' in self .schema :
185
- properties = None
202
+ one_of_properties = None
186
203
for one_of_schema in self .schema / 'oneOf' :
187
204
try :
188
- unmarshalled = self ._unmarshal_properties (value )
205
+ unmarshalled = self ._clone (one_of_schema ).unmarshal_raw (
206
+ value )
189
207
except (UnmarshalError , ValueError ):
190
208
pass
191
209
else :
192
- if properties is not None :
210
+ if one_of_properties is not None :
193
211
log .warning ("multiple valid oneOf schemas found" )
194
212
continue
195
- properties = unmarshalled
213
+ one_of_properties = unmarshalled
196
214
197
- if properties is None :
215
+ if one_of_properties is None :
198
216
log .warning ("valid oneOf schema not found" )
217
+ else :
218
+ properties .update (one_of_properties )
199
219
200
220
elif 'anyOf' in self .schema :
201
- properties = None
221
+ any_of_properties = None
202
222
for any_of_schema in self .schema / 'anyOf' :
203
223
try :
204
- unmarshalled = self ._unmarshal_properties (value )
224
+ unmarshalled = self ._clone (any_of_schema ).unmarshal_raw (
225
+ value )
205
226
except (UnmarshalError , ValueError ):
206
227
pass
207
228
else :
208
- properties = unmarshalled
229
+ any_of_properties = unmarshalled
209
230
break
210
231
211
- if properties is None :
232
+ if any_of_properties is None :
212
233
log .warning ("valid anyOf schema not found" )
213
-
214
- else :
215
- properties = self ._unmarshal_properties (value )
216
-
217
- if 'x-model' in self .schema :
218
- name = self .schema ['x-model' ]
219
- return self .model_factory .create (properties , name = name )
220
-
221
- return properties
222
-
223
- def _unmarshal_properties (self , value ):
224
- properties = {}
234
+ else :
235
+ properties .update (any_of_properties )
225
236
226
237
for prop_name , prop in get_all_properties (self .schema ).items ():
227
238
read_only = prop .getkey ('readOnly' , False )
0 commit comments