From d16739a83a20e1729e08dbcbbc155be15972d146 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 22 May 2021 15:45:20 -0400 Subject: Json schema validation improvements (#1697) * Create new JsonSchema class * Add proxy handler * Update tests * Update validation scripts * Update backend * Update audio downloader * Update options util * Update dictionary importer * Update json schema file reference * Remove old json-schema.js * Rename new json-schema.js * Update file names * Rename class --- dev/dictionary-validate.js | 6 +++--- dev/schema-validate.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'dev') diff --git a/dev/dictionary-validate.js b/dev/dictionary-validate.js index 29f2eae4..83889fc8 100644 --- a/dev/dictionary-validate.js +++ b/dev/dictionary-validate.js @@ -27,7 +27,7 @@ vm.execute([ 'js/general/cache-map.js', 'js/data/json-schema.js' ]); -const JsonSchemaValidator = vm.get('JsonSchemaValidator'); +const JsonSchema = vm.get('JsonSchema'); function readSchema(relativeFileName) { @@ -46,7 +46,7 @@ async function validateDictionaryBanks(zip, fileNameFormat, schema) { if (!file) { break; } const data = JSON.parse(await file.async('string')); - new JsonSchemaValidator().validate(data, schema); + new JsonSchema(schema).validate(data); ++index; } @@ -61,7 +61,7 @@ async function validateDictionary(archive, schemas) { const index = JSON.parse(await indexFile.async('string')); const version = index.format || index.version; - new JsonSchemaValidator().validate(index, schemas.index); + new JsonSchema(schemas.index).validate(index); await validateDictionaryBanks(archive, 'term_bank_?.json', version === 1 ? schemas.termBankV1 : schemas.termBankV3); await validateDictionaryBanks(archive, 'term_meta_bank_?.json', schemas.termMetaBankV3); diff --git a/dev/schema-validate.js b/dev/schema-validate.js index 45285700..77fbd0c8 100644 --- a/dev/schema-validate.js +++ b/dev/schema-validate.js @@ -25,7 +25,7 @@ vm.execute([ 'js/general/cache-map.js', 'js/data/json-schema.js' ]); -const JsonSchemaValidator = vm.get('JsonSchemaValidator'); +const JsonSchema = vm.get('JsonSchema'); function main() { @@ -47,7 +47,7 @@ function main() { console.log(`Validating ${dataFileName}...`); const dataSource = fs.readFileSync(dataFileName, {encoding: 'utf8'}); const data = JSON.parse(dataSource); - new JsonSchemaValidator().validate(data, schema); + new JsonSchema(schema).validate(data); const end = performance.now(); console.log(`No issues detected (${((end - start) / 1000).toFixed(2)}s)`); } catch (e) { -- cgit v1.2.3