16
16
from openapi_core .schema .schemas .enums import SchemaFormat , SchemaType
17
17
from openapi_core .schema .schemas .exceptions import (
18
18
InvalidSchemaValue , UndefinedSchemaProperty , MissingSchemaProperty ,
19
- OpenAPISchemaError , NoOneOfSchema , MultipleOneOfSchema , NoValidSchema ,
19
+ OpenAPISchemaError , NoValidSchema ,
20
20
UndefinedItemsSchema , InvalidCustomFormatSchemaValue , InvalidSchemaProperty ,
21
21
UnmarshallerStrictTypeError ,
22
22
)
23
23
from openapi_core .schema .schemas .util import (
24
24
forcebool , format_date , format_datetime , format_byte , format_uuid ,
25
25
format_number ,
26
26
)
27
- from openapi_core .schema .schemas .validators import (
28
- TypeValidator , AttributeValidator , OAS30Validator ,
29
- )
27
+ from openapi_core .schema .schemas .validators import OAS30Validator
30
28
31
29
log = logging .getLogger (__name__ )
32
30
@@ -49,36 +47,6 @@ class Schema(object):
49
47
DEFAULT_UNMARSHAL_CALLABLE_GETTER = {
50
48
}
51
49
52
- STRING_FORMAT_CALLABLE_GETTER = {
53
- SchemaFormat .NONE : Format (text_type , TypeValidator (text_type )),
54
- SchemaFormat .PASSWORD : Format (text_type , TypeValidator (text_type )),
55
- SchemaFormat .DATE : Format (
56
- format_date , TypeValidator (date , exclude = datetime )),
57
- SchemaFormat .DATETIME : Format (format_datetime , TypeValidator (datetime )),
58
- SchemaFormat .BINARY : Format (binary_type , TypeValidator (binary_type )),
59
- SchemaFormat .UUID : Format (format_uuid , TypeValidator (UUID )),
60
- SchemaFormat .BYTE : Format (format_byte , TypeValidator (text_type )),
61
- }
62
-
63
- NUMBER_FORMAT_CALLABLE_GETTER = {
64
- SchemaFormat .NONE : Format (format_number , TypeValidator (
65
- integer_types + (float , ), exclude = bool )),
66
- SchemaFormat .FLOAT : Format (float , TypeValidator (float )),
67
- SchemaFormat .DOUBLE : Format (float , TypeValidator (float )),
68
- }
69
-
70
- TYPE_VALIDATOR_CALLABLE_GETTER = {
71
- SchemaType .ANY : lambda x : True ,
72
- SchemaType .BOOLEAN : TypeValidator (bool ),
73
- SchemaType .INTEGER : TypeValidator (integer_types , exclude = bool ),
74
- SchemaType .NUMBER : TypeValidator (
75
- integer_types + (float , ), exclude = bool ),
76
- SchemaType .STRING : TypeValidator (
77
- text_type , date , datetime , binary_type , UUID ),
78
- SchemaType .ARRAY : TypeValidator (list , tuple ),
79
- SchemaType .OBJECT : AttributeValidator ('__dict__' ),
80
- }
81
-
82
50
def __init__ (
83
51
self , schema_type = None , model = None , properties = None , items = None ,
84
52
schema_format = None , required = None , default = None , nullable = False ,
@@ -304,11 +272,12 @@ def _unmarshal_any(self, value, custom_formatters=None, strict=True):
304
272
continue
305
273
else :
306
274
if result is not None :
307
- raise MultipleOneOfSchema (self .type )
275
+ log .warning ("multiple valid oneOf schemas found" )
276
+ continue
308
277
result = unmarshalled
309
278
310
279
if result is None :
311
- raise NoOneOfSchema ( self . type )
280
+ log . warning ( "valid oneOf schema not found" )
312
281
313
282
return result
314
283
else :
@@ -321,7 +290,8 @@ def _unmarshal_any(self, value, custom_formatters=None, strict=True):
321
290
except (OpenAPISchemaError , TypeError ):
322
291
continue
323
292
324
- raise NoValidSchema (value )
293
+ log .warning ("failed to unmarshal any type" )
294
+ return value
325
295
326
296
def _unmarshal_collection (self , value , custom_formatters = None , strict = True ):
327
297
if not isinstance (value , (list , tuple )):
@@ -344,17 +314,18 @@ def _unmarshal_object(self, value, model_factory=None,
344
314
properties = None
345
315
for one_of_schema in self .one_of :
346
316
try :
347
- found_props = self ._unmarshal_properties (
317
+ unmarshalled = self ._unmarshal_properties (
348
318
value , one_of_schema , custom_formatters = custom_formatters )
349
319
except OpenAPISchemaError :
350
320
pass
351
321
else :
352
322
if properties is not None :
353
- raise MultipleOneOfSchema (self .type )
354
- properties = found_props
323
+ log .warning ("multiple valid oneOf schemas found" )
324
+ continue
325
+ properties = unmarshalled
355
326
356
327
if properties is None :
357
- raise NoOneOfSchema ( self . type )
328
+ log . warning ( "valid oneOf schema not found" )
358
329
359
330
else :
360
331
properties = self ._unmarshal_properties (
@@ -398,10 +369,8 @@ def _unmarshal_properties(self, value, one_of_schema=None,
398
369
if not prop .nullable and not prop .default :
399
370
continue
400
371
prop_value = prop .default
401
- try :
402
- properties [prop_name ] = prop .unmarshal (
403
- prop_value , custom_formatters = custom_formatters )
404
- except OpenAPISchemaError as exc :
405
- raise InvalidSchemaProperty (prop_name , exc )
372
+
373
+ properties [prop_name ] = prop .unmarshal (
374
+ prop_value , custom_formatters = custom_formatters )
406
375
407
376
return properties
0 commit comments