function validate(json, schema) { // ignore validation if no schema if (schema === undefined) return Promise.resolve(); const valid = tv4.validate(json, schema); if (!valid) { debug(tv4.error.dataPath); debug(tv4.error.message); return Promise.reject(tv4.error); } return Promise.resolve(); }
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."); } }