From 79d24410d28052801738124338ca8affd350ddf0 Mon Sep 17 00:00:00 2001 From: Maciej Barelkowski Date: Fri, 24 Nov 2023 12:04:02 +0100 Subject: [PATCH] fix: disallow subscription binding for `bpmn:SendTask` The property is not allowed for messages to be sent so it does not make sense to make it templatable. --- .../CHANGELOG.md | 4 + .../src/defs/template.json | 81 ++++++++++++++++++- ...scription-property-invalid-element-type.js | 66 +++++++++++++++ ...ption-property-invalid-event-definition.js | 6 +- .../test/spec/validationSpec.js | 3 + 5 files changed, 154 insertions(+), 6 deletions(-) create mode 100644 packages/zeebe-element-templates-json-schema/test/fixtures/message-subscription-property-invalid-element-type.js diff --git a/packages/zeebe-element-templates-json-schema/CHANGELOG.md b/packages/zeebe-element-templates-json-schema/CHANGELOG.md index 02aa65e..2a19165 100644 --- a/packages/zeebe-element-templates-json-schema/CHANGELOG.md +++ b/packages/zeebe-element-templates-json-schema/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to [@camunda/zeebe-element-templates-json-schema](https://gi ___Note:__ Yet to be released changes appear here._ +## 0.16.1 + +* `FIX`: disallow `bpmn:Message#zeebe:subscription#property` binding for `bpmn:SendTask` + ## 0.16.0 * `FEAT`: support `isActive` condition ([#120](https://github.com/camunda/element-templates-json-schema/pull/120)) diff --git a/packages/zeebe-element-templates-json-schema/src/defs/template.json b/packages/zeebe-element-templates-json-schema/src/defs/template.json index 6229ff6..0f505d7 100644 --- a/packages/zeebe-element-templates-json-schema/src/defs/template.json +++ b/packages/zeebe-element-templates-json-schema/src/defs/template.json @@ -9,11 +9,87 @@ "binding": { "properties": { "type": { + "const": "bpmn:Message#property" + } + }, + "required": [ + "type" + ] + } + }, + "required": [ + "binding" + ] + } + } + }, + "required": [ + "properties" + ] + }, + "then": { + "required": [ + "elementType" + ], + "properties": { + "elementType": { + "required": [ + "value" + ], + "properties": { + "value": { + "enum": [ + "bpmn:ReceiveTask", + "bpmn:SendTask", + "bpmn:StartEvent", + "bpmn:IntermediateCatchEvent", + "bpmn:IntermediateThrowEvent", + "bpmn:BoundaryEvent", + "bpmn:EndEvent" + ] + } + }, + "allOf": [ + { + "if": { + "properties": { + "value": { "enum": [ - "bpmn:Message#property", - "bpmn:Message#zeebe:subscription#property" + "bpmn:StartEvent", + "bpmn:IntermediateCatchEvent", + "bpmn:IntermediateThrowEvent", + "bpmn:BoundaryEvent", + "bpmn:EndEvent" + ] } + } + }, + "then": { + "eventDefinition": { + "const": "bpmn:MessageEventDefinition" + }, + "required": [ + "eventDefinition" + ] + } + } + ] + } + } + } + }, + { + "if": { + "properties": { + "properties": { + "contains": { + "properties": { + "binding": { + "properties": { + "type": { + "const": "bpmn:Message#zeebe:subscription#property" + } }, "required": [ "type" @@ -43,7 +119,6 @@ "value": { "enum": [ "bpmn:ReceiveTask", - "bpmn:SendTask", "bpmn:StartEvent", "bpmn:IntermediateCatchEvent", "bpmn:IntermediateThrowEvent", diff --git a/packages/zeebe-element-templates-json-schema/test/fixtures/message-subscription-property-invalid-element-type.js b/packages/zeebe-element-templates-json-schema/test/fixtures/message-subscription-property-invalid-element-type.js new file mode 100644 index 0000000..840d38e --- /dev/null +++ b/packages/zeebe-element-templates-json-schema/test/fixtures/message-subscription-property-invalid-element-type.js @@ -0,0 +1,66 @@ +export const template = { + 'name': 'InvalidElementType', + 'id': 'com.camunda.example.InvalidElementType', + 'appliesTo': [ + 'bpmn:Task' + ], + 'elementType': { + value: 'bpmn:SendTask' + }, + 'properties': [ + { + 'label': 'foo', + 'type': 'String', + 'binding': { + 'type': 'bpmn:Message#zeebe:subscription#property', + 'name': 'correlationKey' + } + } + ] +}; + +export const errors = [ + { + dataPath: '/elementType/value', + keyword: 'enum', + schemaPath: '#/allOf/1/allOf/1/then/properties/elementType/properties/value/enum', + params: { + 'allowedValues': [ + 'bpmn:ReceiveTask', + 'bpmn:StartEvent', + 'bpmn:IntermediateCatchEvent', + 'bpmn:IntermediateThrowEvent', + 'bpmn:BoundaryEvent', + 'bpmn:EndEvent' + ] + }, + message: 'should be equal to one of the allowed values' + }, + { + keyword: 'if', + dataPath: '', + schemaPath: '#/allOf/1/allOf/1/if', + params: { + 'failingKeyword': 'then' + }, + message: 'should match "then" schema' + }, + { + dataPath: '', + keyword: 'type', + message: 'should be array', + params: { + type: 'array', + }, + schemaPath: '#/oneOf/1/type', + }, + { + dataPath: '', + keyword: 'oneOf', + message: 'should match exactly one schema in oneOf', + params: { + passingSchemas: null + }, + schemaPath: '#/oneOf' + } +]; diff --git a/packages/zeebe-element-templates-json-schema/test/fixtures/message-subscription-property-invalid-event-definition.js b/packages/zeebe-element-templates-json-schema/test/fixtures/message-subscription-property-invalid-event-definition.js index e2c6385..69ff192 100644 --- a/packages/zeebe-element-templates-json-schema/test/fixtures/message-subscription-property-invalid-event-definition.js +++ b/packages/zeebe-element-templates-json-schema/test/fixtures/message-subscription-property-invalid-event-definition.js @@ -23,7 +23,7 @@ export const errors = [ { keyword: 'required', dataPath: '/elementType', - schemaPath: '#/allOf/1/allOf/0/then/properties/elementType/allOf/0/then/required', + schemaPath: '#/allOf/1/allOf/1/then/properties/elementType/allOf/0/then/required', params: { missingProperty: 'eventDefinition' }, @@ -36,12 +36,12 @@ export const errors = [ 'params': { 'failingKeyword': 'then' }, - 'schemaPath': '#/allOf/1/allOf/0/then/properties/elementType/allOf/0/if' + 'schemaPath': '#/allOf/1/allOf/1/then/properties/elementType/allOf/0/if' }, { keyword: 'if', dataPath: '', - schemaPath: '#/allOf/1/allOf/0/if', + schemaPath: '#/allOf/1/allOf/1/if', params: { 'failingKeyword': 'then' }, diff --git a/packages/zeebe-element-templates-json-schema/test/spec/validationSpec.js b/packages/zeebe-element-templates-json-schema/test/spec/validationSpec.js index 6e9e66b..de6e79b 100644 --- a/packages/zeebe-element-templates-json-schema/test/spec/validationSpec.js +++ b/packages/zeebe-element-templates-json-schema/test/spec/validationSpec.js @@ -313,6 +313,9 @@ describe('validation', function() { testTemplate('message-subscription-property-invalid-event-definition'); + + + testTemplate('message-subscription-property-invalid-element-type'); });