From 4702a68ad1dcbbc4896fef0f2ca5ff1b08064ea4 Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Wed, 11 Nov 2026 14:33:46 +0200 Subject: [PATCH] adjust variables schema --- .../dynamic_variables_schema.js | 51 +++++++------------ 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/app/javascript/template_builder/dynamic_variables_schema.js b/app/javascript/template_builder/dynamic_variables_schema.js index 64869bc34..3a702f8fc 100644 --- a/app/javascript/template_builder/dynamic_variables_schema.js +++ b/app/javascript/template_builder/dynamic_variables_schema.js @@ -436,29 +436,28 @@ function hasBlankKey (keyString) { return !keyString || keyString.split('.').some((key) => !key.trim()) } +function digProperties (properties, keys) { + return keys.reduce((current, key) => { + if (!current[key]) current[key] = { type: 'object', properties: {} } + + const item = current[key].type === 'array' ? current[key].items : current[key] + + if (!item.properties) { + item.type = 'object' + item.properties = {} + } + + return item.properties + }, properties) +} + function assignNestedSchema (propertiesHash, parentProperties, keyString, value) { if (hasBlankKey(keyString)) return const keys = keyString.split('.') const lastKey = keys.pop() - let currentLevel = null - - if (keys.length > 0 && parentProperties[keys[0]]) { - currentLevel = keys.reduce((current, key) => { - if (!current[key]) current[key] = { type: 'object', properties: {} } - - return current[key].properties - }, parentProperties) - } - - if (!currentLevel) { - currentLevel = keys.reduce((current, key) => { - if (!current[key]) current[key] = { type: 'object', properties: {} } - - return current[key].properties - }, propertiesHash) - } + const currentLevel = digProperties(keys.length > 0 && parentProperties[keys[0]] ? parentProperties : propertiesHash, keys) currentLevel[lastKey] = value } @@ -469,23 +468,7 @@ function assignNestedSchemaWithPriority (propertiesHash, parentProperties, keySt const keys = keyString.split('.') const lastKey = keys.pop() - let currentLevel = null - - if (keys.length > 0 && parentProperties[keys[0]]) { - currentLevel = keys.reduce((current, key) => { - if (!current[key]) current[key] = { type: 'object', properties: {} } - - return current[key].properties - }, parentProperties) - } - - if (!currentLevel) { - currentLevel = keys.reduce((current, key) => { - if (!current[key]) current[key] = { type: 'object', properties: {} } - - return current[key].properties - }, propertiesHash) - } + const currentLevel = digProperties(keys.length > 0 && parentProperties[keys[0]] ? parentProperties : propertiesHash, keys) const existing = currentLevel[lastKey]