From 867928b48b72d5318c6c98917d5ed519a88096d5 Mon Sep 17 00:00:00 2001 From: Maciej Barelkowski Date: Wed, 15 Nov 2023 12:33:15 +0100 Subject: [PATCH] feat: support receive and send task templating Related to https://github.com/camunda/camunda-modeler/issues/3573 --- .../src/defs/element-type.json | 7 --- .../src/defs/template.json | 55 +++++++++++++++-- ...ssage-property-invalid-event-definition.js | 15 ++++- .../test/fixtures/message-property-valid.js | 60 +++++++++++++------ ...ption-property-invalid-event-definition.js | 11 +++- .../message-subscription-property-valid.js | 60 +++++++++++++------ 6 files changed, 153 insertions(+), 55 deletions(-) diff --git a/packages/zeebe-element-templates-json-schema/src/defs/element-type.json b/packages/zeebe-element-templates-json-schema/src/defs/element-type.json index a98390d..d9c89c2 100644 --- a/packages/zeebe-element-templates-json-schema/src/defs/element-type.json +++ b/packages/zeebe-element-templates-json-schema/src/defs/element-type.json @@ -12,13 +12,6 @@ }, { "if": { - "properties": { - "eventDefinition": { - "enum": [ - "bpmn:MessageEventDefinition" - ] - } - }, "required": [ "eventDefinition" ] 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 28ffe5c..6229ff6 100644 --- a/packages/zeebe-element-templates-json-schema/src/defs/template.json +++ b/packages/zeebe-element-templates-json-schema/src/defs/template.json @@ -19,21 +19,64 @@ "type" ] } - } + }, + "required": [ + "binding" + ] } } - } + }, + "required": [ + "properties" + ] }, "then": { + "required": [ + "elementType" + ], "properties": { "elementType": { + "required": [ + "value" + ], "properties": { - "eventDefinition": { - "const": "bpmn:MessageEventDefinition" + "value": { + "enum": [ + "bpmn:ReceiveTask", + "bpmn:SendTask", + "bpmn:StartEvent", + "bpmn:IntermediateCatchEvent", + "bpmn:IntermediateThrowEvent", + "bpmn:BoundaryEvent", + "bpmn:EndEvent" + ] } }, - "required": [ - "eventDefinition" + "allOf": [ + { + "if": { + "properties": { + "value": { + "enum": [ + "bpmn:StartEvent", + "bpmn:IntermediateCatchEvent", + "bpmn:IntermediateThrowEvent", + "bpmn:BoundaryEvent", + "bpmn:EndEvent" + + ] + } + } + }, + "then": { + "eventDefinition": { + "const": "bpmn:MessageEventDefinition" + }, + "required": [ + "eventDefinition" + ] + } + } ] } } diff --git a/packages/zeebe-element-templates-json-schema/test/fixtures/message-property-invalid-event-definition.js b/packages/zeebe-element-templates-json-schema/test/fixtures/message-property-invalid-event-definition.js index b387c7f..b783feb 100644 --- a/packages/zeebe-element-templates-json-schema/test/fixtures/message-property-invalid-event-definition.js +++ b/packages/zeebe-element-templates-json-schema/test/fixtures/message-property-invalid-event-definition.js @@ -1,6 +1,6 @@ export const template = { - 'name': 'MissingBindingName', - 'id': 'com.camunda.example.MissingBindingName', + 'name': 'MissingEventDefinition', + 'id': 'com.camunda.example.MissingEventDefinition', 'appliesTo': [ 'bpmn:IntermediateCatchEvent' ], @@ -23,12 +23,21 @@ export const errors = [ { keyword: 'required', dataPath: '/elementType', - schemaPath: '#/allOf/1/allOf/0/then/properties/elementType/required', + schemaPath: '#/allOf/1/allOf/0/then/properties/elementType/allOf/0/then/required', params: { missingProperty: 'eventDefinition' }, message: 'should have required property \'eventDefinition\'' }, + { + 'dataPath': '/elementType', + 'keyword': 'if', + 'message': 'should match "then" schema', + 'params': { + 'failingKeyword': 'then' + }, + 'schemaPath': '#/allOf/1/allOf/0/then/properties/elementType/allOf/0/if' + }, { keyword: 'if', dataPath: '', diff --git a/packages/zeebe-element-templates-json-schema/test/fixtures/message-property-valid.js b/packages/zeebe-element-templates-json-schema/test/fixtures/message-property-valid.js index d3ba8bb..b15b793 100644 --- a/packages/zeebe-element-templates-json-schema/test/fixtures/message-property-valid.js +++ b/packages/zeebe-element-templates-json-schema/test/fixtures/message-property-valid.js @@ -1,23 +1,45 @@ -export const template = { - 'name': 'MissingBindingName', - 'id': 'com.camunda.example.MissingBindingName', - 'appliesTo': [ - 'bpmn:IntermediateCatchEvent' - ], - 'elementType': { - value: 'bpmn:IntermediateCatchEvent', - eventDefinition: 'bpmn:MessageEventDefinition' +export const template = [ + { + 'name': 'ValidTemplateEvent', + 'id': 'com.camunda.example.ValidTemplateEvent', + 'appliesTo': [ + 'bpmn:IntermediateCatchEvent' + ], + 'elementType': { + value: 'bpmn:IntermediateCatchEvent', + eventDefinition: 'bpmn:MessageEventDefinition' + }, + 'properties': [ + { + 'label': 'foo', + 'type': 'String', + 'binding': { + 'type': 'bpmn:Message#property', + 'name': 'name' + } + } + ] }, - 'properties': [ - { - 'label': 'foo', - 'type': 'String', - 'binding': { - 'type': 'bpmn:Message#property', - 'name': 'name' + { + 'name': 'ValidTemplateReceiveTask', + 'id': 'com.camunda.example.ValidTemplateReceiveTask', + 'appliesTo': [ + 'bpmn:Task' + ], + 'elementType': { + value: 'bpmn:ReceiveTask' + }, + 'properties': [ + { + 'label': 'foo', + 'type': 'String', + 'binding': { + 'type': 'bpmn:Message#property', + 'name': 'name' + } } - } - ] -}; + ] + } +]; export const errors = null; 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 a57050b..e2c6385 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,12 +23,21 @@ export const errors = [ { keyword: 'required', dataPath: '/elementType', - schemaPath: '#/allOf/1/allOf/0/then/properties/elementType/required', + schemaPath: '#/allOf/1/allOf/0/then/properties/elementType/allOf/0/then/required', params: { missingProperty: 'eventDefinition' }, message: 'should have required property \'eventDefinition\'' }, + { + 'dataPath': '/elementType', + 'keyword': 'if', + 'message': 'should match "then" schema', + 'params': { + 'failingKeyword': 'then' + }, + 'schemaPath': '#/allOf/1/allOf/0/then/properties/elementType/allOf/0/if' + }, { keyword: 'if', dataPath: '', diff --git a/packages/zeebe-element-templates-json-schema/test/fixtures/message-subscription-property-valid.js b/packages/zeebe-element-templates-json-schema/test/fixtures/message-subscription-property-valid.js index 3427090..231d687 100644 --- a/packages/zeebe-element-templates-json-schema/test/fixtures/message-subscription-property-valid.js +++ b/packages/zeebe-element-templates-json-schema/test/fixtures/message-subscription-property-valid.js @@ -1,23 +1,45 @@ -export const template = { - 'name': 'MissingBindingName', - 'id': 'com.camunda.example.MissingBindingName', - 'appliesTo': [ - 'bpmn:IntermediateCatchEvent' - ], - 'elementType': { - value: 'bpmn:IntermediateCatchEvent', - eventDefinition: 'bpmn:MessageEventDefinition' +export const template = [ + { + 'name': 'ValidTemplateEvent', + 'id': 'com.camunda.example.ValidTemplateEvent', + 'appliesTo': [ + 'bpmn:IntermediateCatchEvent' + ], + 'elementType': { + value: 'bpmn:IntermediateCatchEvent', + eventDefinition: 'bpmn:MessageEventDefinition' + }, + 'properties': [ + { + 'label': 'foo', + 'type': 'String', + 'binding': { + 'type': 'bpmn:Message#zeebe:subscription#property', + 'name': 'correlationKey' + } + } + ] }, - 'properties': [ - { - 'label': 'foo', - 'type': 'String', - 'binding': { - 'type': 'bpmn:Message#zeebe:subscription#property', - 'name': 'correlationKey' + { + 'name': 'ValidTemplateReceiveTask', + 'id': 'com.camunda.example.ValidTemplateReceiveTask', + 'appliesTo': [ + 'bpmn:Task' + ], + 'elementType': { + value: 'bpmn:ReceiveTask' + }, + 'properties': [ + { + 'label': 'foo', + 'type': 'String', + 'binding': { + 'type': 'bpmn:Message#zeebe:subscription#property', + 'name': 'correlationKey' + } } - } - ] -}; + ] + } +]; export const errors = null;