mirror of
https://github.com/docusealco/docuseal
synced 2026-11-16 08:12:32 -05:00
adjust variables schema
This commit is contained in:
1 parent
704bb2219e
commit
4702a68ad1
1 file changed
+17
-34
@@ -436,29 +436,28 @@ function hasBlankKey (keyString) {
|
|||||||
return !keyString || keyString.split('.').some((key) => !key.trim())
|
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) {
|
function assignNestedSchema (propertiesHash, parentProperties, keyString, value) {
|
||||||
if (hasBlankKey(keyString)) return
|
if (hasBlankKey(keyString)) return
|
||||||
|
|
||||||
const keys = keyString.split('.')
|
const keys = keyString.split('.')
|
||||||
const lastKey = keys.pop()
|
const lastKey = keys.pop()
|
||||||
|
|
||||||
let currentLevel = null
|
const currentLevel = digProperties(keys.length > 0 && parentProperties[keys[0]] ? parentProperties : propertiesHash, keys)
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
currentLevel[lastKey] = value
|
currentLevel[lastKey] = value
|
||||||
}
|
}
|
||||||
@@ -469,23 +468,7 @@ function assignNestedSchemaWithPriority (propertiesHash, parentProperties, keySt
|
|||||||
const keys = keyString.split('.')
|
const keys = keyString.split('.')
|
||||||
const lastKey = keys.pop()
|
const lastKey = keys.pop()
|
||||||
|
|
||||||
let currentLevel = null
|
const currentLevel = digProperties(keys.length > 0 && parentProperties[keys[0]] ? parentProperties : propertiesHash, keys)
|
||||||
|
|
||||||
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 existing = currentLevel[lastKey]
|
const existing = currentLevel[lastKey]
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user