Skip to content

Instantly share code, notes, and snippets.

@runk
Created June 20, 2017 04:36
Show Gist options
  • Save runk/647785d6e9b563952d3149eebfcbfd86 to your computer and use it in GitHub Desktop.
Save runk/647785d6e9b563952d3149eebfcbfd86 to your computer and use it in GitHub Desktop.
const validator = require('is-my-json-valid');
const schema = {
required: true,
type: 'object',
properties: {
id: { type: 'string', required: true },
combined: {
required: false,
type: 'array',
items: { $ref: '#product' },
},
},
additionalProperties: false,
};
const opts = {
greedy: true,
verbose: true,
schemas: {
product: schema,
},
};
const a = {
id: 'a',
}
const b = {
id: 'b',
combined: [a]
}
const c = {
id: 'c',
combined: [b, a]
}
const validate = validator(schema, opts);
validate(a)
console.log('a: ', validate.errors)
validate(b)
console.log('b: ', validate.errors)
validate(c)
console.log('c: ', validate.errors)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment