From 9bee4afaab8b89613e5e504829bdd4fae204e134 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Wed, 1 Jun 2022 14:29:37 +0200 Subject: support schema v2 and dependencies on mappings --- common/jsonschema.js | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'common') 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 = "(?[^/]*)"; +const major_number_re = "(?[1-9][0-9]*)"; +const minor_number_re = "(?:[1-9][0-9]*|0)"; +const numbers_rest_re = `(?:\\.${minor_number_re})*`; +const version_re = `(?${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) -- cgit v1.2.3