diff --git a/packages/element-templates-json-schema-shared/src/base-error-messages.json b/packages/element-templates-json-schema-shared/src/base-error-messages.json index 0fe58cc..66b56d2 100644 --- a/packages/element-templates-json-schema-shared/src/base-error-messages.json +++ b/packages/element-templates-json-schema-shared/src/base-error-messages.json @@ -149,5 +149,20 @@ "property": "missing property name for condition" } } + }, + { + "path": [ + "definitions", + "properties", + "allOf", + 0, + "items", + "allOf", + 1, + "allOf", + 0, + "then" + ], + "errorMessage": "Invalid condition.property, must be different than property.id" } ] \ No newline at end of file diff --git a/packages/element-templates-json-schema-shared/src/defs/condition.json b/packages/element-templates-json-schema-shared/src/defs/condition.json index cd4a579..4e62ad9 100644 --- a/packages/element-templates-json-schema-shared/src/defs/condition.json +++ b/packages/element-templates-json-schema-shared/src/defs/condition.json @@ -63,6 +63,56 @@ ] } }, + "allOf": [ + { + "$comment": "property#condition should not depend on property#id", + "if": { + "required": [ + "id", + "condition" + ], + "properties": { + "condition": { + "anyOf": [ + { + "required": [ + "property" + ], + "properties": { + "property": { + "const": { + "$data": "2/id" + } + } + } + }, + { + "required": [ + "allMatch" + ], + "allMatch": { + "contains": { + "properties": { + "property": { + "const": { + "$data": "2/id" + } + } + } + } + } + } + ] + } + } + }, + "then": { + "not": { + "required": [ "condition" ] + } + } + } + ], "properties": { "id": { "type": "string", diff --git a/packages/element-templates-json-schema-shared/test/helpers/index.js b/packages/element-templates-json-schema-shared/test/helpers/index.js index 1a3eb5c..f0f484f 100644 --- a/packages/element-templates-json-schema-shared/test/helpers/index.js +++ b/packages/element-templates-json-schema-shared/test/helpers/index.js @@ -15,7 +15,8 @@ function createValidator(schema, errors) { const ajv = new Ajv({ allErrors: true, - strict: false + strict: false, + $data: true }); AjvErrors(ajv); diff --git a/packages/zeebe-element-templates-json-schema/test/fixtures/condition-allMatch-on-itself.js b/packages/zeebe-element-templates-json-schema/test/fixtures/condition-allMatch-on-itself.js new file mode 100644 index 0000000..58cc35a --- /dev/null +++ b/packages/zeebe-element-templates-json-schema/test/fixtures/condition-allMatch-on-itself.js @@ -0,0 +1,69 @@ +export const template = { + 'name': 'Condition', + 'id': 'example.com.condition', + 'appliesTo': [ + 'bpmn:ServiceTask' + ], + 'properties': [ + { + 'id': 'myId', + 'label': 'input 1', + 'type': 'String', + 'binding': { + 'type': 'property', + 'name': 'input1' + }, + 'condition': { + 'allMatch': [ + { + 'type': 'simple', + property: 'myId', + equals: 'text' + } + ] + } + } + ] +}; + +export const errors = [ + { + keyword: 'errorMessage', + dataPath: '/properties/0', + schemaPath: '#/allOf/0/items/allOf/1/allOf/0/then/errorMessage', + params: { + errors: [ + { + keyword: 'not', + dataPath: '/properties/0', + schemaPath: '#/allOf/0/items/allOf/1/allOf/0/then/not', + params: {}, + message: 'should NOT be valid', + emUsed: true + } + ] + }, + message: 'Invalid condition.property, must be different than property.id' + }, + { + keyword: 'if', + dataPath: '/properties/0', + schemaPath: '#/allOf/0/items/allOf/1/allOf/0/if', + params: { failingKeyword: 'then' }, + message: 'should match "then" schema' + }, + { + keyword: 'type', + dataPath: '', + schemaPath: '#/oneOf/1/type', + params: { type: 'array' }, + message: 'should be array' + }, + { + keyword: 'oneOf', + dataPath: '', + schemaPath: '#/oneOf', + params: { passingSchemas: null }, + message: 'should match exactly one schema in oneOf' + } +]; diff --git a/packages/zeebe-element-templates-json-schema/test/fixtures/condition-on-itself.js b/packages/zeebe-element-templates-json-schema/test/fixtures/condition-on-itself.js new file mode 100644 index 0000000..4c15a4c --- /dev/null +++ b/packages/zeebe-element-templates-json-schema/test/fixtures/condition-on-itself.js @@ -0,0 +1,64 @@ +export const template = { + 'name': 'Condition', + 'id': 'example.com.condition', + 'appliesTo': [ + 'bpmn:ServiceTask' + ], + 'properties': [ + { + 'id': 'myId', + 'label': 'input 1', + 'type': 'String', + 'binding': { + 'type': 'property', + 'name': 'input1' + }, + 'condition': { + property: 'myId', + equals: 'text' + } + } + ] +}; + +export const errors = [ + { + keyword: 'errorMessage', + dataPath: '/properties/0', + schemaPath: '#/allOf/0/items/allOf/1/allOf/0/then/errorMessage', + params: { + errors: [ + { + keyword: 'not', + dataPath: '/properties/0', + schemaPath: '#/allOf/0/items/allOf/1/allOf/0/then/not', + params: {}, + message: 'should NOT be valid', + emUsed: true + } + ] + }, + message: 'Invalid condition.property, must be different than property.id' + }, + { + keyword: 'if', + dataPath: '/properties/0', + schemaPath: '#/allOf/0/items/allOf/1/allOf/0/if', + params: { failingKeyword: 'then' }, + message: 'should match "then" schema' + }, + { + keyword: 'type', + dataPath: '', + schemaPath: '#/oneOf/1/type', + params: { type: 'array' }, + message: 'should be array' + }, + { + keyword: 'oneOf', + dataPath: '', + schemaPath: '#/oneOf', + params: { passingSchemas: null }, + message: 'should match exactly one schema in oneOf' + } +]; diff --git a/packages/zeebe-element-templates-json-schema/test/fixtures/condition.js b/packages/zeebe-element-templates-json-schema/test/fixtures/condition.js index 0a91480..7cf9101 100644 --- a/packages/zeebe-element-templates-json-schema/test/fixtures/condition.js +++ b/packages/zeebe-element-templates-json-schema/test/fixtures/condition.js @@ -80,6 +80,7 @@ export const template = { } }, { + 'id': 'someId', 'label': 'default condition type', 'type': 'String', 'condition': { 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 4503863..c6c2eb2 100644 --- a/packages/zeebe-element-templates-json-schema/test/spec/validationSpec.js +++ b/packages/zeebe-element-templates-json-schema/test/spec/validationSpec.js @@ -289,6 +289,12 @@ describe('validation', function() { testTemplate('condition-dropdown-choices-invalid'); + + + testTemplate('condition-on-itself'); + + + testTemplate('condition-allMatch-on-itself'); });