forked from osmlab/name-suggestion-index
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.js
29 lines (26 loc) · 1.08 KB
/
validate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const colors = require('colors/safe');
const Validator = require('jsonschema').Validator;
const filters = require('./config/filters.json');
const canonical = require('./config/canonical.json');
const filtersSchema = require('./schema/filters.json');
const canonicalSchema = require('./schema/canonical.json');
validateSchema('config/filters.json', filters, filtersSchema);
validateSchema('config/canonical.json', canonical, canonicalSchema);
// Perform JSON Schema validation
function validateSchema(fileName, object, schema) {
const v = new Validator();
const validationErrors = v.validate(object, schema).errors;
if (validationErrors.length) {
console.error(colors.red('\nError - Schema validation:'));
console.error(' ' + colors.yellow(fileName + ': '));
validationErrors.forEach(e => {
if (e.property) {
console.error(' ' + colors.yellow(e.property + ' ' + e.message));
} else {
console.error(' ' + colors.yellow(e));
}
});
console.error();
process.exit(1);
}
}