Closed dhbarnett closed 12 years ago
Edited: Sorry, Missed the end of the .py
Ok, This was my misunderstanding. Apparently additionalItems doesn't signify repetition of the current scope, it is a container for what the items should be. The following worked as I had expected. I'm closing but adding my example in case this could be useful for others.
inner = { "type" : "object", "properties" : { "a" : {"type" : "string", "required" : True}, "b" : {"type" : "array", "items" : [ {"type" : "string", "required" : True}, ], 'required' : True, }, "c" : {"type" : "string", "required" : True}, } }
testschema = { "type" : "array", "items" : [ inner ], 'minItems' : 1, 'additionalItems' : inner, 'required' : True }
f = open('test.json2', 'r') data = simplejson.load(f) schema = testschema
if not validictory.validate(data,schema): print "Success!" else: print "Failure!"
First, thanks a lot for this tool, it's very nice!
However, it is my understanding that an array with additionalItems set to True should match each item against the schema. I'm either misunderstanding the usage (first time using validictory) or it's not working.
below is a test script and dataset;
jsontest.py
import simplejson import validictory
f = open('test.json2', 'r') data = simplejson.load(f) schema = { "type" : "array", "items" : [ {"type" : "object", "properties" : { "a" : {"type" : "string", "required" : True}, "b" : {"type" : "array", "items" : [ {"type" : "string", "required" : True}, ], 'required' : True, }, "c" : {"type" : "string", "required" : True}, } } ], 'minItems' : 1, 'additionalItems' : True, 'required' : True } if not validictory.validate(data,schema): print "Success!" else: print "Failure!"
test.json2
[ {"a" : "A", "b" : ["B"], "c" : "C" }, {"a" : "D", "b" : ["E"], "c" : "F" } ]
This validates as I would expect and prints "Success!".
If I remove an item from the first set (e.g. "a" : "A") it fails to validate and prints "Failure!"
But, if I remove an item from the 2nd data set (e.g. "a" : "D") it validates successfully.
I appreciate any feedback.
-Dave
P.S. I'm using version 0.8.3