I would like to validate that a property called "foo" contains an array of "bar" objects.
Using TV4 for validation all works as expected if I use an array as the value of foo however if I specify something other than an array such as a string or an integer validation passes when it should not.
var json = { "foo" : { "one" : "bar" }};
Passes as expected with a correctly formatted array.
var json = { "foo" : { "bar" : "error" }};
Fails as expected with in-correct formatted array.
var json = { "foo" : 2 };
Passes event though foo should be an array.
Below is the full code.
var should = require("should");
var validator = require("tv4");
var barSchema = {
"id": "bar",
"type" : "object",
"properties": {
"one": {
"type": "string"
}
},
"required": ["one"],
"additionalProperties": false
}
var fooSchema = {
"id" : "foo",
"title": "foo",
"type": "object",
"properties": {
"foo" : {
"type:" : "array",
"items": {"$ref":"bar"}
}
},
"required": [
"foo"
]
}
describe("foo with integer", function() {
it("should result in an error message", function(){
var json = {
"foo" : 2
}
validator.addSchema(barSchema);
var result = validator.validate(json, fooSchema);
// above should fail but it passes
});
});