camunda / element-templates-json-schema

JSON Schema for (Camunda) Element Templates
10 stars 7 forks source link

Disallow properties depending on itself #125

Open barmac opened 10 months ago

barmac commented 10 months ago

Describe the Bug

Right now, the schema allows a property to depend on itself. Specifically, the condition#property can take any value, and this can also be the id of the conditioned property. This leads to infinite loop which should be prevented via the JSON schema.

Steps to Reproduce

Check the conversation: https://camunda.slack.com/archives/C0693F1NFK5/p1704872988839289

Expected Behavior

Template should be rejected by the validator.

Environment


Discovered via https://camunda.slack.com/archives/C0693F1NFK5/p1704872988839289

barmac commented 10 months ago

We could also make sure that the condition#property value is one of the already existing property#ids.

barmac commented 10 months ago

We could use $data for this: https://json-schema.org/blog/posts/hyperborea#referencing-other-parts-of-the-schema

barmac commented 10 months ago

I experimented with $data, and this is the result: https://github.com/camunda/element-templates-json-schema/compare/main...125-disallow-properties-depending-on-itself?body=&expand=1

The solution works but requires to enable $data: true in the Ajv validator. The error message displayed in the editor is quite cryptic:

image

barmac commented 10 months ago

However, the cryptic error message can be adjusted thanks to the error-messages extension.

barmac commented 10 months ago

OK so actually the result from VSCode that I showed above is incorrect. VSCode does not handle $data as in ajv, so it doesn't matter whether we implement the constraint in the JSON schema or programmatically in the validator.

barmac commented 7 months ago

128 was reverted so this should be open again.