From 71326b26a0192cdf8790da5c4ed9a99873ca04a2 Mon Sep 17 00:00:00 2001 From: Martin Stamm Date: Mon, 4 Mar 2024 09:41:56 +0100 Subject: [PATCH] fix: enforce string value for `feel: required` --- .../src/defs/properties.json | 19 +++++ .../test/fixtures/feel-value-mismatch.js | 81 +++++++++++++++++++ .../test/spec/validationSpec.js | 3 + 3 files changed, 103 insertions(+) create mode 100644 packages/zeebe-element-templates-json-schema/test/fixtures/feel-value-mismatch.js diff --git a/packages/zeebe-element-templates-json-schema/src/defs/properties.json b/packages/zeebe-element-templates-json-schema/src/defs/properties.json index cf40cb5..5aae5cb 100644 --- a/packages/zeebe-element-templates-json-schema/src/defs/properties.json +++ b/packages/zeebe-element-templates-json-schema/src/defs/properties.json @@ -254,6 +254,25 @@ } } } + }, + { + "if": { + "properties": { + "feel": { + "const": "required" + } + }, + "required": [ + "feel" + ] + }, + "then": { + "properties": { + "value": { + "type": "string" + } + } + } } ], "properties": { diff --git a/packages/zeebe-element-templates-json-schema/test/fixtures/feel-value-mismatch.js b/packages/zeebe-element-templates-json-schema/test/fixtures/feel-value-mismatch.js new file mode 100644 index 0000000..191ed5f --- /dev/null +++ b/packages/zeebe-element-templates-json-schema/test/fixtures/feel-value-mismatch.js @@ -0,0 +1,81 @@ +export const template = { + name: 'Pattern Template', + id: 'com.example.PatternTemplate', + appliesTo: [ + 'bpmn:Task' + ], + properties: [ + { + type: 'Text', + binding: { + type: 'zeebe:property', + name: 'prop' + }, + feel: 'required', + value: 'valid' + }, + { + type: 'Boolean', + binding: { + type: 'zeebe:property', + name: 'prop' + }, + feel: 'required', + value: true + }, + { + type: 'Number', + binding: { + type: 'zeebe:property', + name: 'prop' + }, + feel: 'required', + value: 123 + }, + ] +}; + +export const errors = [ + { + keyword: 'type', + dataPath: '/properties/1/value', + schemaPath: '#/allOf/1/items/allOf/9/then/properties/value/type', + params: { type: 'string' }, + message: 'should be string' + }, + { + keyword: 'if', + dataPath: '/properties/1', + schemaPath: '#/allOf/1/items/allOf/9/if', + params: { failingKeyword: 'then' }, + message: 'should match "then" schema' + }, + { + keyword: 'type', + dataPath: '/properties/2/value', + schemaPath: '#/allOf/1/items/allOf/9/then/properties/value/type', + params: { type: 'string' }, + message: 'should be string' + }, + { + keyword: 'if', + dataPath: '/properties/2', + schemaPath: '#/allOf/1/items/allOf/9/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' + } +]; \ No newline at end of file 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 79db9c7..641f724 100644 --- a/packages/zeebe-element-templates-json-schema/test/spec/validationSpec.js +++ b/packages/zeebe-element-templates-json-schema/test/spec/validationSpec.js @@ -145,6 +145,9 @@ describe('validation', function() { testTemplate('feel-type-mismatch'); + testTemplate('feel-value-mismatch'); + + testTemplate('language');