Project

General

Profile

« Previous | Next » 

Revision 9bee4afa

Added by koszko over 1 year ago

support schema v2 and dependencies on mappings

View differences:

html/install.js
49 49
#FROM html/DOM_helpers.js  IMPORT clone_template, Showable
50 50
#FROM common/entities.js   IMPORT item_id_string, version_string, get_files
51 51
#FROM common/misc.js       IMPORT sha256_async AS compute_sha256
52
#FROM common/jsonschema.js IMPORT haketilo_validator, haketilo_schemas
52
#FROM common/jsonschema.js IMPORT haketilo_validator, haketilo_schemas, \
53
                                  haketilo_schema_name_regex
53 54

  
54 55
#FROM html/repo_query_cacher_client.js IMPORT indirect_fetch
55 56

  
......
203 204

  
204 205
	const captype = item_type[0].toUpperCase() + item_type.substring(1);
205 206

  
206
	const $id =
207
	      `https://hydrilla.koszko.org/schemas/api_${item_type}_description-1.0.1.schema.json`;
208
	const schema = haketilo_schemas[$id];
209
	const result = haketilo_validator.validate(json, schema);
210
	if (result.errors.length > 0) {
211
	    const reg = new RegExp(schema.allOf[2].properties.$schema.pattern);
212
	    if (json.$schema && !reg.test(json.$schema)) {
207
	const nonconforming_format_error_msg =
208
	      `${captype} ${item_id_string(id, ver)} was served using a nonconforming response format.`;
209

  
210
	try {
211
	    const match = haketilo_schema_name_regex.exec(json.$schema);
212
	    var major_schema_version = match.groups.major;
213

  
214
	    if (!["1", "2"].includes(major_schema_version)) {
213 215
		const msg = `${captype} ${item_id_string(id, ver)} was served using unsupported Hydrilla API version. You might need to update Haketilo.`;
214
		return work.err(result.errors, msg);
216
		return work.err(null, msg);
215 217
	    }
216

  
217
	    const msg = `${captype} ${item_id_string(id, ver)} was served using a nonconforming response format.`;
218
	    return work.err(result.errors, msg);
218
	} catch(e) {
219
	    return work.err(e, nonconforming_format_error_msg);
219 220
	}
220 221

  
222
	const schema_name = `api_${item_type}_description-${major_schema_version}.schema.json`;
223

  
224
	const schema = haketilo_schemas[schema_name];
225
	const result = haketilo_validator.validate(json, schema);
226
	if (result.errors.length > 0)
227
	    return work.err(result.errors, nonconforming_format_error_msg);
228

  
221 229
	const scripts = item_type === "resource" && json.scripts;
222 230
	const files = json.source_copyright.concat(scripts || []);
223 231

  
......
229 237
		process_item(work, "resource", res_ref.identifier);
230 238
	}
231 239

  
240
	if (major_schema_version >= 2) {
241
	    for (const map_ref of (json.required_mappings || []))
242
		process_item(work, "mapping", map_ref.identifier);
243
	}
244

  
232 245
	/*
233 246
	 * At this point we already have JSON definition of the item and we
234 247
	 * triggered processing of its dependencies. We now have to verify if

Also available in: Unified diff