@@ -32,14 +32,14 @@ class Schema(object):
32
32
SchemaFormat .DATE .value : format_date ,
33
33
})
34
34
35
- VALIDATOR_CALLABLE_GETTER = {
35
+ TYPE_VALIDATOR_CALLABLE_GETTER = {
36
36
None : lambda x : x ,
37
37
SchemaType .BOOLEAN : TypeValidator (bool ),
38
38
SchemaType .INTEGER : TypeValidator (integer_types , exclude = bool ),
39
39
SchemaType .NUMBER : TypeValidator (integer_types , float , exclude = bool ),
40
40
SchemaType .STRING : TypeValidator (binary_type , text_type ),
41
41
SchemaType .ARRAY : TypeValidator (list , tuple ),
42
- SchemaType .OBJECT : AttributeValidator ('__class__ ' ),
42
+ SchemaType .OBJECT : AttributeValidator ('__dict__ ' ),
43
43
}
44
44
45
45
def __init__ (
@@ -242,35 +242,35 @@ def _unmarshal_properties(self, value, one_of_schema=None):
242
242
return properties
243
243
244
244
def get_validator_mapping (self ):
245
- mapping = self .VALIDATOR_CALLABLE_GETTER .copy ()
246
- mapping .update ({
245
+ mapping = {
247
246
SchemaType .OBJECT : self ._validate_object ,
248
- })
247
+ }
249
248
250
249
return defaultdict (lambda : lambda x : x , mapping )
251
250
252
251
def validate (self , value ):
253
252
if value is None :
254
253
if not self .nullable :
255
254
raise InvalidSchemaValue ("Null value for non-nullable schema" )
256
- return self .default
257
-
258
- validator_mapping = self .get_validator_mapping ()
259
- validator_callable = validator_mapping [self .type ]
255
+ return
260
256
261
- if not validator_callable (value ):
257
+ # type validation
258
+ type_validator_callable = self .TYPE_VALIDATOR_CALLABLE_GETTER [
259
+ self .type ]
260
+ if not type_validator_callable (value ):
262
261
raise InvalidSchemaValue (
263
262
"Value of {0} not valid type of {1}" .format (
264
263
value , self .type .value )
265
264
)
266
265
266
+ # structure validation
267
+ validator_mapping = self .get_validator_mapping ()
268
+ validator_callable = validator_mapping [self .type ]
269
+ validator_callable (value )
270
+
267
271
return value
268
272
269
273
def _validate_object (self , value ):
270
- if not hasattr (value , '__dict__' ):
271
- raise InvalidSchemaValue (
272
- "Value of {0} not an object" .format (value ))
273
-
274
274
properties = value .__dict__
275
275
276
276
if self .one_of :
0 commit comments