-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
25 lines (20 loc) · 674 Bytes
/
index.js
File metadata and controls
25 lines (20 loc) · 674 Bytes
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
const Ajv = require("ajv");
const fs = require("fs");
const path = require("path");
const ajv = new Ajv();
const validateSchema = (event) => {
const schemaName = event.key;
const schemaDir = schemaName.replace(/\./g, '/');
const schemaPath = path.join(__dirname, `/schemas/${schemaDir}/${event.value.properties.event_version}.json`);
const schema = JSON.parse(fs.readFileSync(schemaPath, "utf8"));
const validate = ajv.compile(schema);
const result = validate(event);
if (result) {
console.log("Event is valid");
} else {
console.log("Event is invalid");
console.log(validate.errors);
}
return result;
}
module.exports = validateSchema;