From d7cf019b4a8266e8022d82d8d5433c4605921a98 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 22 May 2021 17:56:44 -0400 Subject: Json schema improvements (#1698) * Simplify schema multi-push/pop * Reverse order of schema path * Reverse order of value path * Simplify schema path structure * Rename for better clarity --- ext/js/language/dictionary-importer.js | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'ext/js/language') diff --git a/ext/js/language/dictionary-importer.js b/ext/js/language/dictionary-importer.js index 9365683b..a0806a3a 100644 --- a/ext/js/language/dictionary-importer.js +++ b/ext/js/language/dictionary-importer.js @@ -253,8 +253,8 @@ class DictionaryImporter { } _formatSchemaError(e, fileName) { - const valuePathString = this._getSchemaErrorPathString(e.valuePath, 'dictionary'); - const schemaPathString = this._getSchemaErrorPathString(e.schemaPath, 'schema'); + const valuePathString = this._getSchemaErrorPathString(e.valueStack, 'dictionary'); + const schemaPathString = this._getSchemaErrorPathString(e.schemaStack, 'schema'); const e2 = new Error(`Dictionary has invalid data in '${fileName}' for value '${valuePathString}', validated against '${schemaPathString}': ${e.message}`); e2.data = e; @@ -265,16 +265,23 @@ class DictionaryImporter { _getSchemaErrorPathString(infoList, base='') { let result = base; for (const {path} of infoList) { - switch (typeof path) { - case 'string': - if (result.length > 0) { - result += '.'; + const pathArray = Array.isArray(path) ? path : [path]; + for (const pathPart of pathArray) { + if (pathPart === null) { + result = base; + } else { + switch (typeof pathPart) { + case 'string': + if (result.length > 0) { + result += '.'; + } + result += pathPart; + break; + case 'number': + result += `[${pathPart}]`; + break; } - result += path; - break; - case 'number': - result += `[${path}]`; - break; + } } } return result; -- cgit v1.2.3