Skip to content

Commit

Permalink
Validate layer.refId against layer ids
Browse files Browse the repository at this point in the history
  • Loading branch information
mbasaglia authored Aug 9, 2024
1 parent 4adbb64 commit ce4f1ff
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/static/js/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ce4f1ff

Please sign in to comment.