From fcb5a167ad65b51f7f8ee87ebf51284446d11081 Mon Sep 17 00:00:00 2001 From: Martin Stamm Date: Mon, 4 Mar 2024 09:17:42 +0100 Subject: [PATCH] fix: allow value type `Number` for Number fields closes #138 --- .../src/defs/base-properties.json | 27 ++++++++++++++++++- .../test/fixtures/number-value.js | 11 +++++++- .../test/fixtures/number-value.js | 20 +++++++++++++- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/packages/element-templates-json-schema-shared/src/defs/base-properties.json b/packages/element-templates-json-schema-shared/src/defs/base-properties.json index ba5c154..9fcf9fb 100644 --- a/packages/element-templates-json-schema-shared/src/defs/base-properties.json +++ b/packages/element-templates-json-schema-shared/src/defs/base-properties.json @@ -24,9 +24,33 @@ "choices" ] } - }, + }, { "$ref": "condition.json" + }, + { + "if": { + "properties": { + "type": { + "not": { + "const": "Number" + } + } + }, + "required": [ + "type" + ] + }, + "then": { + "properties": { + "value": { + "type": [ + "string", + "boolean" + ] + } + } + } } ], "properties": { @@ -34,6 +58,7 @@ "$id": "#/properties/property/value", "type": [ "string", + "number", "boolean" ], "description": "The value of a control field." diff --git a/packages/element-templates-json-schema/test/fixtures/number-value.js b/packages/element-templates-json-schema/test/fixtures/number-value.js index 8f9a3ec..f5d16a4 100644 --- a/packages/element-templates-json-schema/test/fixtures/number-value.js +++ b/packages/element-templates-json-schema/test/fixtures/number-value.js @@ -21,7 +21,7 @@ export const errors = [ { keyword: 'type', dataPath: '/properties/0/value', - schemaPath: '#/allOf/0/items/properties/value/type', + schemaPath: '#/allOf/0/items/allOf/2/then/properties/value/type', params: { type: [ 'string', @@ -30,6 +30,15 @@ export const errors = [ }, message: 'should be string,boolean' }, + { + dataPath: '/properties/0', + keyword: 'if', + message: 'should match "then" schema', + params: { + failingKeyword: 'then' + }, + schemaPath: '#/allOf/0/items/allOf/2/if' + }, { dataPath: '', keyword: 'type', diff --git a/packages/zeebe-element-templates-json-schema/test/fixtures/number-value.js b/packages/zeebe-element-templates-json-schema/test/fixtures/number-value.js index 59e0c40..1a003e4 100644 --- a/packages/zeebe-element-templates-json-schema/test/fixtures/number-value.js +++ b/packages/zeebe-element-templates-json-schema/test/fixtures/number-value.js @@ -13,6 +13,15 @@ export const template = { 'type': 'property', 'name': 'name' } + }, + { + 'label': 'Am I awesome?', + 'type': 'Number', + 'value': 50, + 'binding': { + 'type': 'zeebe:property', + 'name': 'customProp' + } } ] }; @@ -21,7 +30,7 @@ export const errors = [ { keyword: 'type', dataPath: '/properties/0/value', - schemaPath: '#/allOf/0/items/properties/value/type', + schemaPath: '#/allOf/0/items/allOf/2/then/properties/value/type', params: { type: [ 'string', @@ -30,6 +39,15 @@ export const errors = [ }, message: 'should be string,boolean' }, + { + dataPath: '/properties/0', + keyword: 'if', + message: 'should match "then" schema', + params: { + failingKeyword: 'then' + }, + schemaPath: '#/allOf/0/items/allOf/2/if' + }, { dataPath: '', keyword: 'type',