Revision 9bee4afa
Added by koszko over 1 year ago
common/jsonschema.js | ||
---|---|---|
67 | 67 |
#EXPORT validate |
68 | 68 |
|
69 | 69 |
const haketilo_schemas = [ |
70 |
#INCLUDE schemas/api_query_result-1.0.1.schema.json |
|
70 |
/* 1.x Hydrilla JSON schema series */ |
|
71 |
#INCLUDE schemas/1.x/api_query_result-1.0.1.schema.json |
|
71 | 72 |
, |
72 |
#INCLUDE schemas/api_mapping_description-1.0.1.schema.json |
|
73 |
#INCLUDE schemas/1.x/api_mapping_description-1.0.1.schema.json
|
|
73 | 74 |
, |
74 |
#INCLUDE schemas/api_resource_description-1.0.1.schema.json |
|
75 |
#INCLUDE schemas/1.x/api_resource_description-1.0.1.schema.json
|
|
75 | 76 |
, |
76 |
#INCLUDE schemas/common_definitions-1.0.1.schema.json |
|
77 |
#INCLUDE schemas/1.x/common_definitions-1.0.1.schema.json |
|
78 |
, |
|
79 |
/* 2.x Hydrilla JSON schema series */ |
|
80 |
#INCLUDE schemas/2.x/api_query_result-2.schema.json |
|
81 |
, |
|
82 |
#INCLUDE schemas/2.x/api_mapping_description-2.schema.json |
|
83 |
, |
|
84 |
#INCLUDE schemas/2.x/api_resource_description-2.schema.json |
|
85 |
, |
|
86 |
#INCLUDE schemas/2.x/common_definitions-2.schema.json |
|
77 | 87 |
].reduce((ac, s) => Object.assign(ac, {[s.$id]: s}), {}); |
88 |
|
|
89 |
const name_base_re = "(?<name_base>[^/]*)"; |
|
90 |
const major_number_re = "(?<major>[1-9][0-9]*)"; |
|
91 |
const minor_number_re = "(?:[1-9][0-9]*|0)"; |
|
92 |
const numbers_rest_re = `(?:\\.${minor_number_re})*`; |
|
93 |
const version_re = `(?<ver>${major_number_re}${numbers_rest_re})`; |
|
94 |
const schema_name_re = `${name_base_re}-${version_re}\\.schema\\.json`; |
|
95 |
|
|
96 |
const haketilo_schema_name_regex = new RegExp(schema_name_re); |
|
97 |
|
|
98 |
for (const [$id, schema] of [...Object.entries(haketilo_schemas)]) { |
|
99 |
const match = haketilo_schema_name_regex.exec($id); |
|
100 |
const schema_name = |
|
101 |
`${match.groups.name_base}-${match.groups.major}.schema.json`; |
|
102 |
haketilo_schemas[schema_name] = schema; |
|
103 |
} |
|
104 |
|
|
78 | 105 |
#EXPORT haketilo_schemas |
106 |
#EXPORT haketilo_schema_name_regex |
|
79 | 107 |
|
80 | 108 |
const haketilo_validator = new Validator(); |
81 | 109 |
Object.values(haketilo_schemas) |
Also available in: Unified diff
support schema v2 and dependencies on mappings