Fix nested dictionaries
This commit is contained in:
parent
c7c564fac2
commit
5b0713f1cf
1 changed files with 4 additions and 4 deletions
|
@ -65,20 +65,20 @@ func _check_dictionary_recursive(schema_parent: Dictionary, path: String = "") -
|
||||||
return success
|
return success
|
||||||
|
|
||||||
func evaluate() -> Array[String]:
|
func evaluate() -> Array[String]:
|
||||||
return _evaluate_recursive(str(randf()).repeat(50), schema)
|
return _evaluate_recursive(str(randf()).repeat(50), schema, data)
|
||||||
|
|
||||||
func _evaluate_recursive(random: String, schema_parent: Dictionary, path: String = "") -> Array[String]:
|
func _evaluate_recursive(random: String, schema_parent: Dictionary, data_parent: Dictionary, path: String = "") -> Array[String]:
|
||||||
var failed: Array[String] = []
|
var failed: Array[String] = []
|
||||||
for key in schema_parent:
|
for key in schema_parent:
|
||||||
# Check if key exists in data
|
# Check if key exists in data
|
||||||
if str(data.get(key, random)) == random:
|
if str(data_parent.get(key, random)) == random:
|
||||||
# Does not exist, append error
|
# Does not exist, append error
|
||||||
failed.append(core.stringify_variables("Key %key% is present in schema but missing in data", { "key": path + "/" + key }))
|
failed.append(core.stringify_variables("Key %key% is present in schema but missing in data", { "key": path + "/" + key }))
|
||||||
else:
|
else:
|
||||||
# Exists in data
|
# Exists in data
|
||||||
if typeof(schema[key]) == TYPE_DICTIONARY:
|
if typeof(schema[key]) == TYPE_DICTIONARY:
|
||||||
# Key is of type Dictionary, allow for recursion to happen
|
# Key is of type Dictionary, allow for recursion to happen
|
||||||
failed.append_array(_evaluate_recursive(random, schema[key], path + "/" + key))
|
failed.append_array(_evaluate_recursive(random, schema[key], data[key], path + "/" + key))
|
||||||
else:
|
else:
|
||||||
# Key is not of type Dictionary, evaluate against data
|
# Key is not of type Dictionary, evaluate against data
|
||||||
schema[key].data = data[key]
|
schema[key].data = data[key]
|
||||||
|
|
Loading…
Reference in a new issue