blob: d0e6f8d2a7b0965754048cd9ec4f8fdbd72c387d (
plain)
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
30
31
32
33
34
35
36
37
|
import $RefParser from "@apidevtools/json-schema-ref-parser";
import Ajv2019 from "ajv/dist/2019.js"
import fs from 'fs';
import yaml from 'js-yaml';
function stripIds(schema, first) {
if (schema !== null && typeof schema === 'object') {
if (!first) {
// Every referenced schema we pull in should have its $id and $schema stripped, or ajv complains
// Skip the root object, as that should retain the $schema and $id
delete schema.$id;
delete schema.$schema;
}
for (const key in schema) {
if (schema.hasOwnProperty(key)) {
stripIds(schema[key], false);
}
}
}
}
// Load the main schema and all its referenced schemas
const dereferenced = await $RefParser.dereference('./config/3.0.schema.json');
// Remove $id and $schema from anything but the root
stripIds(dereferenced, true);
const ajv = new Ajv2019({strict: true})
const validator = ajv.compile(dereferenced)
const data = fs.readFileSync('../.rr.yaml', 'utf-8');
const schema = yaml.load(data);
// Validate the file
if (!validator(schema)) {
throw new Error("Errors: " + JSON.stringify(validator.errors))
}
|