1515from openapi_core .schema .schemas ._format import oas30_format_checker
1616from openapi_core .schema .schemas .enums import SchemaFormat , SchemaType
1717from openapi_core .schema .schemas .exceptions import (
18- InvalidSchemaValue , UndefinedSchemaProperty , MissingSchemaProperty ,
19- OpenAPISchemaError , NoValidSchema ,
20- UndefinedItemsSchema , InvalidSchemaProperty ,
18+ CastError , InvalidSchemaValue ,
2119 UnmarshallerError , UnmarshallValueError , UnmarshallError ,
2220)
2321from openapi_core .schema .schemas .util import (
@@ -141,13 +139,6 @@ def get_all_required_properties_names(self):
141139
142140 return set (required )
143141
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-
151142 def get_cast_mapping (self ):
152143 mapping = self .TYPE_CAST_CALLABLE_GETTER .copy ()
153144 mapping .update ({
@@ -167,8 +158,7 @@ def cast(self, value):
167158 try :
168159 return cast_callable (value )
169160 except ValueError :
170- raise InvalidSchemaValue (
171- "Failed to cast value {value} to type {type}" , value , self .type )
161+ raise CastError (value , self .type )
172162
173163 def _cast_collection (self , value ):
174164 return list (map (self .items .cast , value ))
@@ -204,7 +194,7 @@ def validate(self, value, resolver=None):
204194 return validator .validate (value )
205195 except ValidationError :
206196 # TODO: pass validation errors
207- raise InvalidSchemaValue ("Value not valid for schema" , value , self .type )
197+ raise InvalidSchemaValue (value , self .type )
208198
209199 def unmarshal (self , value , custom_formatters = None , strict = True ):
210200 """Unmarshal parameter from the value."""
@@ -310,7 +300,7 @@ def _unmarshal_object(self, value, model_factory=None,
310300 try :
311301 unmarshalled = self ._unmarshal_properties (
312302 value , one_of_schema , custom_formatters = custom_formatters )
313- except OpenAPISchemaError :
303+ except ( UnmarshallError , ValueError ) :
314304 pass
315305 else :
316306 if properties is not None :
@@ -342,10 +332,6 @@ def _unmarshal_properties(self, value, one_of_schema=None,
342332
343333 value_props_names = value .keys ()
344334 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 )
349335
350336 properties = {}
351337 if self .additional_properties is not True :
@@ -358,8 +344,6 @@ def _unmarshal_properties(self, value, one_of_schema=None,
358344 try :
359345 prop_value = value [prop_name ]
360346 except KeyError :
361- if prop_name in all_req_props_names :
362- raise MissingSchemaProperty (prop_name )
363347 if not prop .nullable and not prop .default :
364348 continue
365349 prop_value = prop .default
0 commit comments