camunda / element-templates-json-schema

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

`binding` allows invalid values #109

Open nikku opened 1 year ago

nikku commented 1 year ago

Describe the Bug

The schema validation for binding is insufficient, allowing to set properties not actually relevant to the existing binding type.

Steps to Reproduce

Validate the following template:

{
  "$schema": "https://unpkg.com/browse/@camunda/zeebe-element-templates-json-schema/resources/schema.json",
  "name": "Connector Name",
  "id": "connector-id",
  "appliesTo": ["bpmn:Task"],
  "properties": [
    {
      "type": "String",
      "binding": {
          "type": "zeebe:input",
          "name": "variableName",
          "key": "ONLY_RELEVANT_FOR_HEADERS"
      },
      "value": "=default expression"
    }
  ]
}

See that binding.key is an allowed property, despite only allowed if binding.type === 'zeebe:taskHeader'.

Expected Behavior

We validate known properties of binding, and ensure they are used correctly.

Environment

pinussilvestrus commented 1 year ago

For transparency, in our draft forms JSON schema, we tried out a more modular approach of defining rules, e.g., also for allowed properties of sub schemas. One way to comprehend the fairly high complexity of these if-then-rules. Maybe this helps as an inspiration 👍

nikku commented 1 year ago

Would your approach directly contribute to better validation?

pinussilvestrus commented 1 year ago

This approach validates invalid properties for form field types, such as "if NOT this type, then this property is not allowed". IDEs with JSON schema support as VS Code then create such error messages.

image

nikku commented 1 year ago

Thanks for the update. So this would indeed fix https://github.com/camunda/element-templates-json-schema/issues/110.