summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Berman <Julian+git@GrayVines.com>2012-06-07 19:56:59 -0400
committerJulian Berman <Julian+git@GrayVines.com>2012-06-07 19:56:59 -0400
commit4d6598b98024ccb94cb15d0b6d4fe6443d65818a (patch)
tree4f05d3a8222736513776087bbdc43a8be8accfdd
parent23da7cedc58103d8dd037d6b9144c4e90532037e (diff)
downloadjsonschema-4d6598b98024ccb94cb15d0b6d4fe6443d65818a.tar.gz
Fixed a bug caused by implementation of _SKIPPED
Failing to be able to subclass Validator and implement additional validation for one of the properties that the Validator happens to not validate (like format).
-rw-r--r--jsonschema.py35
1 files changed, 17 insertions, 18 deletions
diff --git a/jsonschema.py b/jsonschema.py
index ca89265..9b8684c 100644
--- a/jsonschema.py
+++ b/jsonschema.py
@@ -199,14 +199,6 @@ class Validator(object):
"""
- _SKIPPED = set([ # handled in:
- "dependencies", "required", # properties
- "exclusiveMinimum", "exclusiveMaximum", # min*/max*
- "default", "description", "format", "id", # no validation needed
- "links", "name", "title",
- "$ref", "$schema", # not yet supported
- ])
-
DEFAULT_TYPES = {
"array" : list, "boolean" : bool, "integer" : int, "null" : type(None),
"number" : (int, float), "object" : dict, "string" : basestring,
@@ -366,18 +358,9 @@ class Validator(object):
def _validate(self, instance, schema):
for k, v in iteritems(schema):
- if k in self._SKIPPED:
- continue
-
validator = getattr(self, "validate_%s" % (k.lstrip("$"),), None)
-
if validator is None:
- self.schema_error(
- self._unknown_property,
- "%r is not a known schema property" % (k,)
- )
- return
-
+ return self.unknown_property(k, instance, schema)
validator(v, instance, schema)
def validate(self, instance, schema):
@@ -402,6 +385,12 @@ class Validator(object):
errors=list(self._errors)
)
+ def unknown_property(self, property, instance, schema):
+ self.schema_error(
+ self._unknown_property,
+ "%r is not a known schema property" % (property,)
+ )
+
def validate_type(self, types, instance, schema):
types = _list(types)
@@ -578,6 +567,16 @@ class Validator(object):
self._validate(instance, subschema)
+for no_op in [ # handled in:
+ "dependencies", "required", # properties
+ "exclusiveMinimum", "exclusiveMaximum", # min*/max*
+ "default", "description", "format", "id", # no validation needed
+ "links", "name", "title",
+ "ref", "schema", # not yet supported
+]:
+ setattr(Validator, "validate_" + no_op, lambda *args, **kwargs : None)
+
+
def _extras_msg(extras):
"""
Create an error message for extra items or properties.