geraintluff / tv4

Tiny Validator for JSON Schema v4
http://geraintluff.github.io/tv4/
Other
1.17k stars 183 forks source link

Multiple validation fails with "required" validator #87

Open kokujin opened 10 years ago

kokujin commented 10 years ago
var schema = {
    "items": {
        "type": "boolean"
    },
    "goats": {
        "type": "string"
    },
    "fishes": {
        "type": "enum"
    },
    "cats": {
        "type": "string"
    },
    required: ['fishes', 'goats']
};
var data2 = {items:true, fishes:'dasdad', goats: 5};
console.log("data 2: " + tv4.validate(data2, schema)); // false
console.log("data 2 error: " + JSON.stringify(tv4.error, null, 4));

This outputs: output --> data 2: true main.js:20 data 2 error: null

geraintluff commented 10 years ago

Your schema seems very malformed. Shouldn't your property definitions be bundled up inside the properties keyword, like this?

geraintluff commented 10 years ago

Also, "type": "enum" doesn't really make sense either. enum is a keyword, used like:

{
    "type": "string",
    "enum": ["one", "two", "many", "lots"]
}