10
10
from openapi_schema_validator ._format import oas30_format_checker
11
11
12
12
from openapi_core .extensions .models .factories import ModelFactory
13
- from openapi_core .schema .schemas import (
14
- get_all_properties , get_all_properties_names
15
- )
13
+ from openapi_core .schema .schemas import get_all_properties
16
14
from openapi_core .unmarshalling .schemas .enums import UnmarshalContext
17
15
from openapi_core .unmarshalling .schemas .exceptions import (
18
16
UnmarshalError , ValidateError , InvalidSchemaValue ,
@@ -187,8 +185,7 @@ def _unmarshal_object(self, value):
187
185
properties = None
188
186
for one_of_schema in self .schema / 'oneOf' :
189
187
try :
190
- unmarshalled = self ._unmarshal_properties (
191
- value , one_of_schema = one_of_schema )
188
+ unmarshalled = self ._unmarshal_properties (value )
192
189
except (UnmarshalError , ValueError ):
193
190
pass
194
191
else :
@@ -204,15 +201,12 @@ def _unmarshal_object(self, value):
204
201
properties = None
205
202
for any_of_schema in self .schema / 'anyOf' :
206
203
try :
207
- unmarshalled = self ._unmarshal_properties (
208
- value , any_of_schema = any_of_schema )
204
+ unmarshalled = self ._unmarshal_properties (value )
209
205
except (UnmarshalError , ValueError ):
210
206
pass
211
207
else :
212
- if properties is not None :
213
- log .warning ("multiple valid anyOf schemas found" )
214
- continue
215
208
properties = unmarshalled
209
+ break
216
210
217
211
if properties is None :
218
212
log .warning ("valid anyOf schema not found" )
@@ -226,37 +220,10 @@ def _unmarshal_object(self, value):
226
220
227
221
return properties
228
222
229
- def _unmarshal_properties (
230
- self , value , one_of_schema = None , any_of_schema = None ):
231
- all_props = get_all_properties (self .schema )
232
- all_props_names = get_all_properties_names (self .schema )
233
-
234
- if one_of_schema is not None :
235
- all_props .update (get_all_properties (one_of_schema ))
236
- all_props_names |= get_all_properties_names (one_of_schema )
237
-
238
- if any_of_schema is not None :
239
- all_props .update (get_all_properties (any_of_schema ))
240
- all_props_names |= get_all_properties_names (any_of_schema )
241
-
242
- value_props_names = list (value .keys ())
243
- extra_props = set (value_props_names ) - set (all_props_names )
244
-
223
+ def _unmarshal_properties (self , value ):
245
224
properties = {}
246
- additional_properties = self .schema .getkey (
247
- 'additionalProperties' , True )
248
- if isinstance (additional_properties , dict ):
249
- additional_prop_schema = self .schema / 'additionalProperties'
250
- for prop_name in extra_props :
251
- prop_value = value [prop_name ]
252
- properties [prop_name ] = self .unmarshallers_factory .create (
253
- additional_prop_schema )(prop_value )
254
- elif additional_properties is True :
255
- for prop_name in extra_props :
256
- prop_value = value [prop_name ]
257
- properties [prop_name ] = prop_value
258
225
259
- for prop_name , prop in list ( all_props . items () ):
226
+ for prop_name , prop in get_all_properties ( self . schema ). items ():
260
227
read_only = prop .getkey ('readOnly' , False )
261
228
if self .context == UnmarshalContext .REQUEST and read_only :
262
229
continue
@@ -273,6 +240,22 @@ def _unmarshal_properties(
273
240
properties [prop_name ] = self .unmarshallers_factory .create (
274
241
prop )(prop_value )
275
242
243
+ additional_properties = self .schema .getkey (
244
+ 'additionalProperties' , True )
245
+ if isinstance (additional_properties , dict ):
246
+ additional_prop_schema = self .schema / 'additionalProperties'
247
+ additional_prop_unmarshaler = self .unmarshallers_factory .create (
248
+ additional_prop_schema )
249
+ for prop_name , prop_value in value .items ():
250
+ if prop_name in properties :
251
+ continue
252
+ properties [prop_name ] = additional_prop_unmarshaler (prop_value )
253
+ elif additional_properties is True :
254
+ for prop_name , prop_value in value .items ():
255
+ if prop_name in properties :
256
+ continue
257
+ properties [prop_name ] = prop_value
258
+
276
259
return properties
277
260
278
261
0 commit comments