node-cqrs-domain icon indicating copy to clipboard operation
node-cqrs-domain copied to clipboard

replace tv4 with is-my-json-valid

Open adrai opened this issue 10 years ago • 2 comments

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

adrai avatar Mar 23 '15 13:03 adrai

branch https://github.com/adrai/node-cqrs-domain/tree/validator

adrai avatar Mar 23 '15 15:03 adrai

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);

adrai avatar Mar 25 '15 14:03 adrai