15
15
from openapi_core .schema .schemas ._format import oas30_format_checker
16
16
from openapi_core .schema .schemas .enums import SchemaFormat , SchemaType
17
17
from openapi_core .schema .schemas .exceptions import (
18
- InvalidSchemaValue , UndefinedSchemaProperty , MissingSchemaProperty ,
19
- OpenAPISchemaError , NoValidSchema ,
20
- UndefinedItemsSchema , InvalidSchemaProperty ,
18
+ CastError , InvalidSchemaValue ,
21
19
UnmarshallerError , UnmarshallValueError , UnmarshallError ,
22
20
)
23
21
from openapi_core .schema .schemas .util import (
@@ -141,13 +139,6 @@ def get_all_required_properties_names(self):
141
139
142
140
return set (required )
143
141
144
- def are_additional_properties_allowed (self , one_of_schema = None ):
145
- return (
146
- (self .additional_properties is not False ) and
147
- (one_of_schema is None or
148
- one_of_schema .additional_properties is not False )
149
- )
150
-
151
142
def get_cast_mapping (self ):
152
143
mapping = self .TYPE_CAST_CALLABLE_GETTER .copy ()
153
144
mapping .update ({
@@ -167,8 +158,7 @@ def cast(self, value):
167
158
try :
168
159
return cast_callable (value )
169
160
except ValueError :
170
- raise InvalidSchemaValue (
171
- "Failed to cast value {value} to type {type}" , value , self .type )
161
+ raise CastError (value , self .type )
172
162
173
163
def _cast_collection (self , value ):
174
164
return list (map (self .items .cast , value ))
@@ -204,7 +194,7 @@ def validate(self, value, resolver=None):
204
194
return validator .validate (value )
205
195
except ValidationError :
206
196
# TODO: pass validation errors
207
- raise InvalidSchemaValue ("Value not valid for schema" , value , self .type )
197
+ raise InvalidSchemaValue (value , self .type )
208
198
209
199
def unmarshal (self , value , custom_formatters = None , strict = True ):
210
200
"""Unmarshal parameter from the value."""
@@ -310,7 +300,7 @@ def _unmarshal_object(self, value, model_factory=None,
310
300
try :
311
301
unmarshalled = self ._unmarshal_properties (
312
302
value , one_of_schema , custom_formatters = custom_formatters )
313
- except OpenAPISchemaError :
303
+ except ( UnmarshallError , ValueError ) :
314
304
pass
315
305
else :
316
306
if properties is not None :
@@ -342,10 +332,6 @@ def _unmarshal_properties(self, value, one_of_schema=None,
342
332
343
333
value_props_names = value .keys ()
344
334
extra_props = set (value_props_names ) - set (all_props_names )
345
- extra_props_allowed = self .are_additional_properties_allowed (
346
- one_of_schema )
347
- if extra_props and not extra_props_allowed :
348
- raise UndefinedSchemaProperty (extra_props )
349
335
350
336
properties = {}
351
337
if self .additional_properties is not True :
@@ -358,8 +344,6 @@ def _unmarshal_properties(self, value, one_of_schema=None,
358
344
try :
359
345
prop_value = value [prop_name ]
360
346
except KeyError :
361
- if prop_name in all_req_props_names :
362
- raise MissingSchemaProperty (prop_name )
363
347
if not prop .nullable and not prop .default :
364
348
continue
365
349
prop_value = prop .default
0 commit comments