aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-06-01 14:29:37 +0200
committerWojtek Kosior <koszko@koszko.org>2022-06-01 14:29:37 +0200
commit9bee4afaab8b89613e5e504829bdd4fae204e134 (patch)
treedb8e133b7c61ab7ddf9e4096a391e5fd2965f060 /common
parent6cce03018786fe1f82014f82525770cca43808d8 (diff)
downloadbrowser-extension-9bee4afaab8b89613e5e504829bdd4fae204e134.tar.gz
browser-extension-9bee4afaab8b89613e5e504829bdd4fae204e134.zip
support schema v2 and dependencies on mappings
Diffstat (limited to 'common')
-rw-r--r--common/jsonschema.js36
1 files changed, 32 insertions, 4 deletions
diff --git a/common/jsonschema.js b/common/jsonschema.js
index cde3fca..3e99cd6 100644
--- a/common/jsonschema.js
+++ b/common/jsonschema.js
@@ -67,15 +67,43 @@ function validate(instance, schema, options) {
#EXPORT validate
const haketilo_schemas = [
-#INCLUDE schemas/api_query_result-1.0.1.schema.json
+ /* 1.x Hydrilla JSON schema series */
+#INCLUDE schemas/1.x/api_query_result-1.0.1.schema.json
,
-#INCLUDE schemas/api_mapping_description-1.0.1.schema.json
+#INCLUDE schemas/1.x/api_mapping_description-1.0.1.schema.json
,
-#INCLUDE schemas/api_resource_description-1.0.1.schema.json
+#INCLUDE schemas/1.x/api_resource_description-1.0.1.schema.json
,
-#INCLUDE schemas/common_definitions-1.0.1.schema.json
+#INCLUDE schemas/1.x/common_definitions-1.0.1.schema.json
+ ,
+ /* 2.x Hydrilla JSON schema series */
+#INCLUDE schemas/2.x/api_query_result-2.schema.json
+ ,
+#INCLUDE schemas/2.x/api_mapping_description-2.schema.json
+ ,
+#INCLUDE schemas/2.x/api_resource_description-2.schema.json
+ ,
+#INCLUDE schemas/2.x/common_definitions-2.schema.json
].reduce((ac, s) => Object.assign(ac, {[s.$id]: s}), {});
+
+const name_base_re = "(?<name_base>[^/]*)";
+const major_number_re = "(?<major>[1-9][0-9]*)";
+const minor_number_re = "(?:[1-9][0-9]*|0)";
+const numbers_rest_re = `(?:\\.${minor_number_re})*`;
+const version_re = `(?<ver>${major_number_re}${numbers_rest_re})`;
+const schema_name_re = `${name_base_re}-${version_re}\\.schema\\.json`;
+
+const haketilo_schema_name_regex = new RegExp(schema_name_re);
+
+for (const [$id, schema] of [...Object.entries(haketilo_schemas)]) {
+ const match = haketilo_schema_name_regex.exec($id);
+ const schema_name =
+ `${match.groups.name_base}-${match.groups.major}.schema.json`;
+ haketilo_schemas[schema_name] = schema;
+}
+
#EXPORT haketilo_schemas
+#EXPORT haketilo_schema_name_regex
const haketilo_validator = new Validator();
Object.values(haketilo_schemas)