Hey there.
On Thursday, April 18, 2013 4:36:34 PM UTC-4, Paul Kavanagh wrote:
I'm not sure how to invoke the format checker.
v = Draft4Validator(test_schema, format_checker=FormatChecker()) #works but doesn't check anything
That looks right. FormatChecker() by itself constructs a thing that knows about all the formats jsonschema knows about (i.e. ones from draft 3 along with ones from draft4). Passing something else in there restricts the format checkers it knows about to just the ones you pass in, so FormatChecker(["email"]) (note that it has to be an *iterable* (list) of names, not just a string), will just know about the "email" format.
It should work though. E.g. I get:
>>> import jsonschema; jsonschema.validate("cow", {"format" : "ipv4"}, format_checker=jsonschema.FormatChecker())
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/jsonschema.py", line 1301, in validate
cls(schema, *args, **kwargs).validate(instance)
File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/jsonschema.py", line 227, in validate
raise error
ValidationError: 'cow' is not a 'ipv4'
Can you post your instance and schema or a reproducing example of something you expect to work but doesn't?
Julian