summaryrefslogtreecommitdiff
path: root/schemas/test.js
diff options
context:
space:
mode:
Diffstat (limited to 'schemas/test.js')
-rw-r--r--schemas/test.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/schemas/test.js b/schemas/test.js
new file mode 100644
index 00000000..d0e6f8d2
--- /dev/null
+++ b/schemas/test.js
@@ -0,0 +1,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))
+}