var schema1 = {
id: 'schema1',
properties: {
foo: {'type': 'string'}
},
additionalProperties: false
};
var schema2 = {
id: 'schema2',
properties: {
bar: {'type': 'string'}
}
};
var schema3 = {
id: 'schema3',
properties: {
baz: {'type': 'string'}
}
};
Ajv = require('ajv');
var ajv = new Ajv({v5: true});
require('ajv-merge-patch')(ajv);
ajv.addSchema(schema1);
ajv.addSchema(schema2);
ajv.addSchema(schema3);
var validate = ajv.compile({
id: 'schema',
$merge: {
source: {
$merge: {
source: { "$ref": "schema1" },
with: { "$ref": "schema2" }
}
},
with: { "$ref": "schema3" }
}
});
console.log(validate({foo:1})); // false
console.log(validate({bar:1})); // false
console.log(validate({baz:1})); // false
console.log(validate({additional:1})); // false
console.log(validate({foo: '1', bar: '2', baz: '3'})); // true