node-cqrs-domain
node-cqrs-domain copied to clipboard
replace tv4 with is-my-json-valid
wait for: https://github.com/mafintosh/is-my-json-valid/issues/38#issuecomment-76299626 and https://github.com/mafintosh/is-my-json-valid/issues/43 and https://github.com/mafintosh/is-my-json-valid/pull/46
branch https://github.com/adrai/node-cqrs-domain/tree/validator
my tmp clipboard:
var validator = require('is-my-json-valid');
var ext = {
type: 'number'
};
var validate = validator({
type: 'object',
properties: {
hello: {
type: 'string',
format: 'only-a'
},
hello2: {
'$ref': '/other'
}
},
required: ['hello', 'hello2']
}, {
schemas: {
'/other2': ext
},
formats: {
// 'only-a': /^a+$/
'only-a': function (data) {
if (data.indexOf('b') >= 0) {
return false;
}
return true;
}
},
verbose: true,
greedy: true
});
console.log(validate({ hello: 'aa', hello2: 3 })); // true
console.log(validate.errors);
console.log(validate.missing);
console.log(validate({ hello: 'ab' })); // false
console.log(validate.errors);