tape("validateConfigSchema", (test) => { const jsonFileRe = /\.json$/i; const resultsFileRe = /\.results\.json$/i; const jsConfigFileRe = /^jsconfig\.json$/i; const wrongTypesFileRe = /wrong-types-in-config-file.json$/i; const testDirectory = __dirname; const testFiles = fs.readdirSync(testDirectory); testFiles.filter(function filterFile(file) { return jsonFileRe.test(file) && !resultsFileRe.test(file) && !jsConfigFileRe.test(file) && !wrongTypesFileRe.test(file); }).forEach(function forFile(file) { const data = fs.readFileSync( path.join(testDirectory, file), helpers.utf8Encoding ); test.ok( tv4.validate(JSON.parse(data), configSchema), file + "\n" + JSON.stringify(tv4.error, null, 2)); }); test.end(); });
function jsonValidate (schema, value, propPath) { if (tv4.validate(value, schema)) { return true; } else if (propPath !== undefined) { let dataPath = propPath ? propPath + "." + tv4.error.dataPath : tv4.error.dataPath; throw ono(tv4.error, { status: 400 }, 'JSON Schema validation error. \nData path: "%s" \nSchema path: "%s"', dataPath, tv4.error.schemaPath); } else { throw ono(tv4.error, { status: 400 }, "JSON Schema validation error."); } }
const validResult = (commandName, result) => { const schema = commands[commandName].schema.res; return tv4.validate(result, schema); }
eval(str.substring(3)); //let wsSchema = [ [....} ] for (let schema of wsSchema) { tv4.addSchema(schema); for (let methodType of ['request', 'response']) { let groupUri = '/' + methodType + '/' + moduleName; let groupSchema = tv4.getSchema(groupUri); if (!groupSchema) continue; let commands = groupSchema.anyOf.map(elm => { return elm['$ref']; }); }; for (let command of commands) { let schema = tv4.getSchema(command); let basePath = groupSchema.basePath; let name = command.split('/').pop(); let commandParam = {