summaryrefslogtreecommitdiff
path: root/schemas/test.js
diff options
context:
space:
mode:
Diffstat (limited to 'schemas/test.js')
-rw-r--r--schemas/test.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/schemas/test.js b/schemas/test.js
new file mode 100644
index 00000000..cd469c3a
--- /dev/null
+++ b/schemas/test.js
@@ -0,0 +1,39 @@
+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 (Object.hasOwn(schema, 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, allErrors: 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(JSON.stringify(validator.errors, null, 2))
+} else {
+ console.log('No errors found in schemas.')
+}