From ce4f1fff00e11489b2ad124d1ad0eea7a6d23914 Mon Sep 17 00:00:00 2001 From: Mattia Basaglia Date: Fri, 9 Aug 2024 18:00:57 +0200 Subject: [PATCH] Validate layer.refId against layer ids --- docs/static/js/validator.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/docs/static/js/validator.js b/docs/static/js/validator.js index f4e8b5f..2b21c4d 100644 --- a/docs/static/js/validator.js +++ b/docs/static/js/validator.js @@ -275,6 +275,12 @@ class Validator "asset_oneof": schema_id, }; + for ( let layer_type of ["image-layer", "precomposition-layer"]) + { + let layer_schema = this.defs.layers[layer_type]; + layer_schema.allOf[1].properties.refId.reference_asset = true; + } + prop_map.finalize(); this.validator = new AjvClass({ @@ -385,6 +391,33 @@ class Validator return false; }, }, + { + keyword: "reference_asset", + validate: function validate_asset_reference(schema, data, parent_schema, data_ctx) + { + validate_asset_reference.errors = []; + + if ( Array.isArray(data_ctx.rootData.assets) ) + { + for ( let asset of data_ctx.rootData.assets ) + { + if ( asset.id === data ) + { + // TODO: Validate asset type? + return true; + } + } + } + + validate_asset_reference.errors.push({ + message: `${JSON.stringify(data)} is not a valid asset id`, + type: "error", + instancePath: data_ctx.instancePath, + parentSchema: parent_schema, + }); + return false; + }, + }, { keyword: "warn_extra_props", validate: function warn_extra_props(schema, data, parent_schema, data_cxt)