bpdusk / jsonschema

Automatically exported from code.google.com/p/jsonschema
0 stars 0 forks source link

Nested Arrays aren't valided correctly #12

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Use schema with an array of objects that have an array of objects as a
property
2. Top array has 3 objects, the 2nd level arrays have 8, 9, and 9 objects

What is the expected output? What do you see instead?
A valid schema. Instead errors are generated for arr[3-8], "arr[3] is
missing and it is not optional". It appears to be a scope problem with the
l var in the for loops inside the checkProp function. I added var l about
line 106 and this appears to have fixed the problem.

if(schema.items){
    //added to fix scope problem looping over arrays
    var l;
    if(schema.items instanceof Array){
        for(i=0,l=value.length; i<l; i++){
            errors.concat(checkProp(value[i],schema.items[i],path,i));
        }
    }else{
        console.debug(value.length);
        for(i=0,l=value.length; i<l; i++){
            errors.concat(checkProp(value[i],schema.items,path,i));
        }
    }                           
}

What version of the product are you using? On what operating system?
b3 on windows in firefox 3

Please provide any additional information below.

Original issue reported on code.google.com by randysjo...@gmail.com on 28 Apr 2009 at 4:20