Created
June 20, 2017 04:36
-
-
Save runk/647785d6e9b563952d3149eebfcbfd86 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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