From 6eb2a38659aa18741a8108c90e51e0d4e22f8488 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 24 Jun 2020 16:29:52 +0100 Subject: [PATCH] validate: loadRemoteJson and remoteJsonCachePath options https://github.com/openactive/conformance-services/issues/22 --- .gitignore | 1 + src/lib/settings.js | 5 +++++ src/lib/validate-raw-data.js | 17 ++++++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..92d287b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/dataModelValidatorRemoteJsonCache diff --git a/src/lib/settings.js b/src/lib/settings.js index bc6512e..60328c5 100644 --- a/src/lib/settings.js +++ b/src/lib/settings.js @@ -1,3 +1,5 @@ +import path from 'path'; + const Settings = { "spiderDataCatalogStartURL": process.env.SPIDER_DATA_CATALOG_START_URL || 'https://www.openactive.io/data-catalogs/data-catalog-collection.jsonld', @@ -15,6 +17,9 @@ const Settings = { "sleepWhileSpiderDataCatalogSeconds": 1, "sleepWhileDownloadRawSeconds": 1, + // this is in cwd() and not /tmp so it works well on Heroku + "dataModelValidatorRemoteJsonCachePath": path.join(process.cwd(), 'dataModelValidatorRemoteJsonCache'), + } export default Settings; diff --git a/src/lib/validate-raw-data.js b/src/lib/validate-raw-data.js index 658cced..9b371aa 100644 --- a/src/lib/validate-raw-data.js +++ b/src/lib/validate-raw-data.js @@ -1,5 +1,18 @@ import { database_pool } from './database.js'; import validator from '@openactive/data-model-validator'; +import Settings from './settings.js'; +import fs from 'fs'; + +const validate_options = { + loadRemoteJson: true, + remoteJsonCachePath: Settings.dataModelValidatorRemoteJsonCachePath, +}; + +async function set_up_for_validation() { + if (!fs.existsSync(validate_options.remoteJsonCachePath)) { + await fs.promises.mkdir(validate_options.remoteJsonCachePath, {recursive:true}); + } +} /* * TODO This will run only one check at a time - add something so it runs several at once! @@ -7,6 +20,8 @@ import validator from '@openactive/data-model-validator'; */ async function validate_raw_data_all() { + await set_up_for_validation(); + const client = await database_pool.connect(); try { while(true) { @@ -31,7 +46,7 @@ async function validate_raw_data_all() { async function validate_raw_data(raw_data) { - const result = await validator.validate(raw_data.data); + const result = await validator.validate(raw_data.data, validate_options); const result_filtered = result.filter(r => r.severity === "failure"); const client = await database_pool.connect();