The following:
{ "tupleTyping":[2,"a"] }
will validate (incorrectly) with the following tupletyping schema:
{ "type":"object", "properties":{ "tupleTyping":{ "type":"array", "items":[ {"type":"string"}, {"type":"number"} ] } } }
I solved that with the following (near line 102):
if (schema.items) {
if(schema.items instanceof Array) {
for (var i =0,l=value.length; i < l; i++) {
errors2.concat(checkProp(value[i],schema.items[i],path,i));
}
}
else {
for (var i =0,l=value.length; i < l; i++) {
errors2.concat(checkProp(value[i],schema.items,path,i));
}
}
}
And I think the (line 78) following code might be useless, because it looks like it is from an old tuple typing implementation:
if (type instanceof Array) { var unionErrors=[]; for (var j = 0; j < type.length; j++) // a union type if (!(unionErrors=checkType(type[j],value)).length) break; if (unionErrors.length) return unionErrors; }
Comment #1
Posted on Dec 4, 2008 by Happy KangarooI made some improvements to check optional and additionalParameters issues: if (schema.items) { if(schema.items instanceof Array) { for (var k = 0,l=value.length; k < l; k++) { if(k < schema.items.length) { errors2.concat(checkProp(value[k],schema.items[k],path,k)); } else { if(schema.additionalProperties !== undefined) { if(schema.additionalProperties === false) { addError("The item " + i + "[" + k + "] is not defined in the objTypeDef and the objTypeDef does not allow additional properties"); } else { errors2.concat(checkProp(value[k],schema.additionalProperties,path,k)); } } } } if(value.length < schema.items.length) { for (var k = value.length; k < schema.items.length; k++) { errors2.concat(checkProp(undefined,schema.items[k],path,k)); } } } else { ...
Comment #2
Posted on Apr 16, 2009 by Swift Panda(No comment was entered for this change.)
Status: Fixed
Labels:
Type-Defect
Priority-Medium