diff --git a/.travis.yml b/.travis.yml index dbc7bc0084b13..92009a703637b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: node_js node_js: - - "6" + - "8" services: - docker env: diff --git a/package.json b/package.json index b4f35cae41f82..23ce0efa24dd7 100644 --- a/package.json +++ b/package.json @@ -10,15 +10,13 @@ "description": "Tests for Azure REST API Specifications", "license": "MIT", "devDependencies": { + "fs-extra": "^3.0.1", "mocha": "*", - "async": "^2.1.4", "glob": "^5.0.14", "json-schema-ref-parser": "^3.1.2", - "lodash": "^3.10.1", "request": "^2.61.0", "z-schema": "^3.16.1", "oav": "^0.4.1", - "underscore": "^1.8.3", "js-yaml": "^3.8.2", "azure-storage": "^2.1.0" }, diff --git a/scripts/getStatus.js b/scripts/getStatus.js index 8394cc3ccac03..c4cfbd0329351 100644 --- a/scripts/getStatus.js +++ b/scripts/getStatus.js @@ -6,38 +6,14 @@ var exec = require('child_process').exec, path = require('path'), fs = require('fs'), glob = require('glob'), - _ = require('underscore'), - oav = require('oav'); + oav = require('oav'), + utils = require("../test/util/utils"); -exports = module.exports; -exports.globPath = path.join(__dirname, '../', '/**/swagger/*.json'); -exports.swaggers = _(glob.sync(exports.globPath)); - -var swaggersToProcess = exports.swaggers; +var swaggersToProcess = utils.swaggers; var finalResult = {}; -var filename = `log_${getTimeStamp()}.log`; +var filename = `log_${utils.getTimeStamp()}.log`; var logFilepath = path.join(getLogDir(), filename); -function getTimeStamp() { - // We pad each value so that sorted directory listings show the files in chronological order - function pad(number) { - if (number < 10) { - return '0' + number; - } - - return number; - } - - var now = new Date(); - return now.getFullYear() - + pad(now.getMonth() + 1) - + pad(now.getDate()) - + "_" - + pad(now.getHours()) - + pad(now.getMinutes()) - + pad(now.getSeconds()); -} - function updateResult(spec, errors, updateLog) { if (!finalResult[spec]) { finalResult[spec] = errors; @@ -47,7 +23,6 @@ function updateResult(spec, errors, updateLog) { if (updateLog) { writeContent(JSON.stringify(finalResult, null, 2)); } - return; } function getLogDir() { @@ -67,7 +42,6 @@ function createLogFile() { if (!fs.existsSync(logFilepath)) { fs.writeFileSync(logFilepath, ''); } - return; } //appends the content to the log file @@ -75,47 +49,32 @@ function writeContent(content) { fs.writeFileSync(logFilepath, content); } -//executes promises sequentially by chaining them. -function executePromisesSequentially(promiseFactories) { - let result = Promise.resolve(); - promiseFactories.forEach(function (promiseFactory) { - result = result.then(promiseFactory); - }); - return result; -}; - //runs the linter on a given swagger spec. -function runLinter(swagger) { - return new Promise((res) => { - let cmd = 'autorest --azure-validator=true --input-file=' + swagger + ' --message-format=json'; - console.log(`\t- Running Linter.`); - exec(cmd, { encoding: 'utf8', maxBuffer: 1024 * 1024 * 64 }, (err, stdout, stderr) => { - let resultObject = []; - if (err) { - console.log(`An error occurred while running the linter on ${swagger}:`); - console.dir(err, { depth: null, colors: true }); - } else { - //console.log('>>>> Actual result...'); - //console.log(resultString); - let resultString = stdout + stderr; - if (resultString.indexOf('{') !== -1) { - resultString = "[" + resultString.substring(resultString.indexOf('{')).trim().replace(/\}\n\{/g, "},\n{") + "]"; - //console.log('>>>>>> Trimmed Result...'); - //console.log(resultString); - try { - resultObject = JSON.parse(resultString); - //console.log('>>>>>> Parsed Result...'); - //console.dir(resultObject, {depth: null, colors: true}); - } catch (e) { - console.log(`An error occurred while executing JSON.parse() on the linter output for ${swagger}:`); - console.dir(resultString); - console.dir(e, { depth: null, colors: true }); - } - } - } - res(resultObject); - }); - }); +async function runLinter(swagger) { + // TODO: update to use config file... but report grouping is by Swagger right now + let cmd = 'autorest --validation --azure-validator --input-file=' + swagger + ' --message-format=json'; + console.log(`\t- Running Linter.`); + const {err, stdout, stderr } = await new Promise(res => exec(cmd, { encoding: 'utf8', maxBuffer: 1024 * 1024 * 64 }, + (err, stdout, stderr) => res({ err: err, stdout: stdout, stderr: stderr }))); + let resultObject = []; + let resultString = stdout + stderr; + //console.log('>>>> Actual result...'); + //console.log(resultString); + if (resultString.indexOf('{') !== -1) { + resultString = "[" + resultString.substring(resultString.indexOf('{')).trim().replace(/\}\n\{/g, "},\n{") + "]"; + //console.log('>>>>>> Trimmed Result...'); + //console.log(resultString); + try { + resultObject = JSON.parse(resultString); + //console.log('>>>>>> Parsed Result...'); + //console.dir(resultObject, {depth: null, colors: true}); + } catch (e) { + console.log(`An error occurred while executing JSON.parse() on the linter output for ${swagger}:`); + console.dir(resultString); + console.dir(e, { depth: null, colors: true }); + } + } + return resultObject; } //runs the semantic validator on a given swagger spec. @@ -123,41 +82,36 @@ function runSemanticValidator(swagger) { console.log('\t- Running Semantic Validator.') return oav.validateSpec(swagger, {consoleLogLevel: 'off'}).then(function (validationResult) { //console.dir(validationResult, { depth: null, colors: true }); - return Promise.resolve(validationResult.validateSpec.errors); + return validationResult.validateSpec.errors; }).catch(function (err) { console.dir(err, { depth: null, colors: true }); }); } +//runs the validation and linting tools on all the swaggers in the repo. +async function runTools(swagger) { + console.log(`Processing "${swagger}":`); + const validationErrors = await runSemanticValidator(swagger); + updateResult(swagger, validationErrors, true); + const linterErrors = await runLinter(swagger); + updateResult(swagger, linterErrors, true); +} + //main function -function runScript() { +async function runScript() { // Useful when debugging a test for a particular swagger. // Just update the regex. That will return an array of filtered items. // swaggersToProcess = swaggersToProcess.filter(function (item) { // return (item.match(/.*arm-network/ig) !== null); // }); createLogFile(); - console.log(`The results will be logged here: "${logFilepath}".`) - let promiseFactories = _(swaggersToProcess).map(function (swagger) { - return function () { return runTools(swagger); }; - }); - return executePromisesSequentially(promiseFactories); -} - -//runs the validation and linting tools on all the swaggers in the repo. -function runTools(swagger) { - console.log(`Processing "${swagger}":`); - return runSemanticValidator(swagger).then(function (validationErrors) { - updateResult(swagger, validationErrors, true); - return swagger; - }).then(function (swagger) { - return runLinter(swagger).then(function (linterErrors) { - updateResult(swagger, linterErrors, true); - //console.dir(finalResult, { depth: null, colors: true }); - return finalResult; - }); - }); + console.log(`The results will be logged here: "${logFilepath}".`); + for (const swagger of swaggersToProcess) { + await runTools(swagger); + } + //console.dir(finalResult, { depth: null, colors: true }); + return finalResult; } //magic starts here -runScript(); \ No newline at end of file +runScript(); diff --git a/scripts/momentOfTruth.js b/scripts/momentOfTruth.js index 547dbcd22fff9..456147a7b4dda 100644 --- a/scripts/momentOfTruth.js +++ b/scripts/momentOfTruth.js @@ -8,7 +8,6 @@ const exec = require('child_process').exec, path = require('path'), util = require('util'), utils = require('../test/util/utils'), - _ = require('underscore'), fs = require('fs'), request = require('request'); @@ -17,7 +16,7 @@ let configsToProcess = utils.getConfigFilesChangedInPR(); let targetBranch = utils.getTargetBranch(); let sourceBranch = utils.getSourceBranch(); let pullRequestNumber = utils.getPullRequestNumber(); -let linterCmd = `autorest --azure-validator --message-format=json `; +let linterCmd = `autorest --validation --azure-validator --message-format=json `; let gitCheckoutCmd = `git checkout ${targetBranch}`; let gitLogCmd = `git log -3`; var filename = `${pullRequestNumber}_${utils.getTimeStamp()}.json`; @@ -50,7 +49,6 @@ function createLogFile() { if (!fs.existsSync(logFilepath)) { fs.writeFileSync(logFilepath, ''); } - return; } //appends the content to the log file @@ -58,49 +56,38 @@ function writeContent(content) { fs.writeFileSync(logFilepath, content); } -//executes promises sequentially by chaining them. -function executePromisesSequentially(promiseFactories) { - let result = Promise.resolve(); - promiseFactories.forEach(function (promiseFactory) { - result = result.then(promiseFactory); - }); - return result; -}; - // Executes linter on given swagger path and returns structured JSON of linter output -function getLinterResult(swaggerPath) { +async function getLinterResult(swaggerPath) { if (swaggerPath === null || swaggerPath === undefined || typeof swaggerPath.valueOf() !== 'string' || !swaggerPath.trim().length) { throw new Error('swaggerPath is a required parameter of type "string" and it cannot be an empty string.'); } - return new Promise((result) => { - let jsonResult = []; - if (!fs.existsSync(swaggerPath)) { - result([]); - return; + let jsonResult = []; + if (!fs.existsSync(swaggerPath)) { + return []; + } + let cmd = linterCmd + swaggerPath; + console.log(`Executing: ${cmd}`); + const {err, stdout, stderr } = await new Promise(res => exec(cmd, { encoding: 'utf8', maxBuffer: 1024 * 1024 * 64 }, + (err, stdout, stderr) => res({ err: err, stdout: stdout, stderr: stderr }))); + + let resultString = stderr; + if (resultString.indexOf('{') !== -1) { + resultString = "[" + resultString.substring(resultString.indexOf('{')).trim().replace(/\}\n\{/g, "},\n{") + "]"; + //console.log('>>>>>> Trimmed Result...'); + //console.log(resultString); + try { + jsonResult = JSON.parse(resultString); + //console.log('>>>>>> Parsed Result...'); + //console.dir(resultObject, {depth: null, colors: true}); + return jsonResult; + } catch (e) { + console.log(`An error occurred while executing JSON.parse() on the linter output for ${swaggerPath}:`); + console.dir(resultString); + console.dir(e, { depth: null, colors: true }); } - let cmd = linterCmd + swaggerPath; - console.log(`Executing: ${cmd}`); - exec(cmd, { encoding: 'utf8', maxBuffer: 1024 * 1024 * 64 }, (err, stdout, stderr) => { - let resultString = stderr; - if (resultString.indexOf('{') !== -1) { - resultString = "[" + resultString.substring(resultString.indexOf('{')).trim().replace(/\}\n\{/g, "},\n{") + "]"; - //console.log('>>>>>> Trimmed Result...'); - //console.log(resultString); - try { - jsonResult = JSON.parse(resultString); - //console.log('>>>>>> Parsed Result...'); - //console.dir(resultObject, {depth: null, colors: true}); - result(jsonResult); - } catch (e) { - console.log(`An error occurred while executing JSON.parse() on the linter output for ${swaggerPath}:`); - console.dir(resultString); - console.dir(e, { depth: null, colors: true }); - result([]); - } - } - }); - }); + } + return []; }; // Uploads the result file to Azure Blob Storage @@ -117,13 +104,11 @@ function uploadToAzureStorage(json) { } // Run linter tool -function runTools(swagger, beforeOrAfter) { +async function runTools(swagger, beforeOrAfter) { console.log(`Processing "${swagger}":`); - return getLinterResult(swagger).then(function (linterErrors) { - console.log(linterErrors); - updateResult(swagger, linterErrors, beforeOrAfter); - return; - }); + const linterErrors = await getLinterResult(swagger); + console.log(linterErrors); + updateResult(swagger, linterErrors, beforeOrAfter); }; // Updates final result json to be written to the output file @@ -135,7 +120,6 @@ function updateResult(spec, errors, beforeOrAfter) { finalResult['files'][spec][beforeOrAfter] = {}; } finalResult['files'][spec][beforeOrAfter] = errors; - return; } //main function @@ -151,22 +135,16 @@ function runScript() { createLogFile(); console.log(`The results will be logged here: "${logFilepath}".`) - let afterPRPromiseFactories = _(configsToProcess).map(function (swagger) { - return function () { return runTools(swagger, 'after'); }; - }); - - let beforePromiseFactories = _(configsToProcess).map(function (swagger) { - return function () { return runTools(swagger, 'before'); }; - }); - - executePromisesSequentially(afterPRPromiseFactories).then(() => { - execSync(`${gitCheckoutCmd}`, { encoding: 'utf8' }); - execSync(`${gitLogCmd}`, { encoding: 'utf8' }); - executePromisesSequentially(beforePromiseFactories).then(() => { - writeContent(JSON.stringify(finalResult, null, 2)); - return uploadToAzureStorage(finalResult); - }) - }); + for (const configFile of configsToProcess) { + await runTools(configFile, 'after'); + } + execSync(`${gitCheckoutCmd}`, { encoding: 'utf8' }); + execSync(`${gitLogCmd}`, { encoding: 'utf8' }); + for (const configFile of configsToProcess) { + await runTools(configFile, 'before'); + } + writeContent(JSON.stringify(finalResult, null, 2)); + return uploadToAzureStorage(finalResult); } // magic starts here diff --git a/test/linter.js b/test/linter.js index fe21efb5f9ffc..de86f2e08c69a 100644 --- a/test/linter.js +++ b/test/linter.js @@ -2,7 +2,7 @@ // Licensed under the MIT License. See License in the project root for license information. 'use strict'; -var _ = require('lodash'), +var execSync = require('child_process').execSync, utils = require('./util/utils'); @@ -13,17 +13,16 @@ describe('AutoRest Linter validation:', function () { // configsToProcess = configsToProcess.filter(function(item) { // return (item.match(/.Microsoft.ContainerRegistry.*2017-03-01.*/ig) !== null); // }); - _(configsToProcess).each(function (config) { - it(config + ' should honor linter validation rules.', function (done) { - var cmd = `autorest --azure-validator ${config} --message-format=json`; + for (const config of configsToProcess) { + it(config + ' should honor linter validation rules.', async function (done) { + var cmd = `autorest --validation --azure-validator ${config} --message-format=json`; console.log(`Executing: ${cmd}`); let result; try { result = execSync(cmd, { encoding: 'utf8' }); - done(); } catch (err) { - done(new Error('AutoRest Linter validation failed.')); + throw new Error('AutoRest Linter validation failed.'); } }); - }).value(); + } }); diff --git a/test/model.js b/test/model.js index de22e7a26f33d..4648425cb72d4 100644 --- a/test/model.js +++ b/test/model.js @@ -2,8 +2,7 @@ // Licensed under the MIT License. See License in the project root for license information. 'use strict'; -var _ = require('lodash'), - assert = require('assert'), +var assert = require('assert'), utils = require('./util/utils'), oav = require('oav'); @@ -14,15 +13,17 @@ describe('Azure swagger model validation using x-ms-examples and examples in spe // swaggersToProcess = swaggersToProcess.filter(function(item) { // return (item.match(/.*Microsoft.Logic.*2016-06-01.*/ig) !== null); // }); - _(swaggersToProcess).each(function (swagger) { - it(swagger + ' should have valid examples.', function (done) { - oav.validateExamples(swagger, null, {consoleLogLevel: 'error'}).then(function (validationResult) { - //console.dir(validationResult, {depth: null, colors: true}); - done(assert(validationResult.validityStatus === true, `swagger "${swagger}" contains model validation errors.`)); - }).catch(function (err) { + for (const swagger of swaggersToProcess) { + it(swagger + ' should have valid examples.', async function () { + try { + const validationResult = await oav.validateExamples(swagger, null, {consoleLogLevel: 'error'}); + return assert( + validationResult.validityStatus === true, + `swagger "${swagger}" contains model validation errors.`); + } catch (err) { console.dir(err, {depth: null, colors: true}); - done(err); - }); + throw err; + } }); - }).value(); + } }); \ No newline at end of file diff --git a/test/semantic.js b/test/semantic.js index 2015ddb94a207..370b052975304 100644 --- a/test/semantic.js +++ b/test/semantic.js @@ -2,8 +2,7 @@ // Licensed under the MIT License. See License in the project root for license information. 'use strict'; -var _ = require('lodash'), - assert = require('assert'), +var assert = require('assert'), utils = require('./util/utils'), oav = require('oav'); @@ -14,17 +13,17 @@ describe('Azure swagger semantic validation:', function () { // swaggersToProcess = swaggersToProcess.filter(function(item) { // return (item.match(/.*Microsoft.Logic.*2016-06-01.*/ig) !== null); // }); - - _(swaggersToProcess).each(function (swagger) { - it(swagger + ' should be semantically valid.', function (done) { - oav.validateSpec(swagger, {consoleLogLevel: 'error'}).then(function (validationResult) { - //console.dir(validationResult, {depth: null, colors: true}); - done(assert(validationResult.validateSpec && validationResult.validateSpec.errors && validationResult.validateSpec.errors.length === 0, - `swagger "${swagger}" contains semantic validation errors.`)); - }).catch(function (err) { + for (const swagger of swaggersToProcess) { + it(swagger + ' should be semantically valid.', async function () { + try { + const validationResult = await oav.validateSpec(swagger, null, {consoleLogLevel: 'error'}); + return assert( + validationResult.validateSpec && validationResult.validateSpec.errors && validationResult.validateSpec.errors.length === 0, + `swagger "${swagger}" contains semantic validation errors.`); + } catch (err) { console.dir(err, {depth: null, colors: true}); - done(err); - }); + throw err; + } }); - }).value(); + } }); \ No newline at end of file diff --git a/test/syntax.js b/test/syntax.js index c0e2f4238bf52..86b7379fef710 100644 --- a/test/syntax.js +++ b/test/syntax.js @@ -5,8 +5,6 @@ var assert = require("assert"), fs = require('fs'), path = require('path'), - _ = require('lodash'), - async = require('async'), RefParser = require('json-schema-ref-parser'), util = require('util'), utils = require('./util/utils'); @@ -25,64 +23,48 @@ var context; describe('Azure swagger schema validation:', function () { - before(function (done) { - utils.initializeValidator(function (err, result) { - if (err) { - done(err); + before(async function () { + const result = await utils.initializeValidator(); + context = result; + }); + + for (const swagger of utils.swaggers) { + it(swagger + ' should be a valid Swagger document.', async function () { + const parsedData = await utils.parseJsonFromFile(swagger); + var valid = context.validator.validate(parsedData, context.extensionSwaggerSchema); + if (!valid) { + var error = context.validator.getLastErrors(); + throw new Error("Schema validation failed: " + util.inspect(error, { depth: null })); } - context = result; - done(); + assert(valid === true); }); - }); + } - _(utils.swaggers).each(function (swagger) { - it(swagger + ' should be a valid Swagger document.', function (done) { - utils.parseJsonFromFile(swagger, function (err, parsedData) { - if (err) { done(err); } - if (parsedData.documents && util.isArray(parsedData.documents)) { - console.log(util.format('Skipping the test for \'%s\' document as it seems to be a composite swagger doc.', swagger)); - done(); - } - var valid = context.validator.validate(parsedData, context.extensionSwaggerSchema); + describe('Azure x-ms-example schema validation:', function () { + for (const example of utils.examples) { + it('x-ms-examples: ' + example + ' should be a valid x-ms-example.', async function () { + const parsedData = await utils.parseJsonFromFile(example); + var valid = context.validator.validate(parsedData, context.exampleSchema); if (!valid) { var error = context.validator.getLastErrors(); throw new Error("Schema validation failed: " + util.inspect(error, { depth: null })); } assert(valid === true); - done(); - }); - }); - }).value(); - - describe('Azure x-ms-example schema validation:', function () { - _(utils.examples).each(function (example) { - it('x-ms-examples: ' + example + ' should be a valid x-ms-example.', function (done) { - utils.parseJsonFromFile(example, function (err, parsedData) { - if (err) { done(err); } - var valid = context.validator.validate(parsedData, context.exampleSchema); - if (!valid) { - var error = context.validator.getLastErrors(); - throw new Error("Schema validation failed: " + util.inspect(error, { depth: null })); - } - assert(valid === true); - done(); - }); }); - }).value(); + } }); }); describe('External file or url references ("$ref") in a swagger spec:', function () { - _(utils.swaggers).each(function (swagger) { - it(swagger + ' should be completely resolvable.', function (done) { + for (const swagger of utils.swaggers) { + it(swagger + ' should be completely resolvable.', async function () { RefParser.bundle(swagger, function (bundleErr, bundleResult) { if (bundleErr) { var msg = swagger + ' has references that cannot be resolved. They are as follows: \n' + util.inspect(bundleErr.message, { depth: null }); console.log(msg); throw new Error(msg); } - done(); }); }); - }).value(); + } }); \ No newline at end of file diff --git a/test/util/utils.js b/test/util/utils.js index 265af173aa5a1..425fe76fba91b 100644 --- a/test/util/utils.js +++ b/test/util/utils.js @@ -3,16 +3,17 @@ 'use strict'; var assert = require("assert"), - fs = require('fs'), + fs = require('fs-extra'), glob = require('glob'), path = require('path'), - _ = require('lodash'), z = require('z-schema'), YAML = require('js-yaml'), request = require('request'), util = require('util'), execSync = require('child_process').execSync; +const asyncJsonRequest = url => new Promise((res, rej) => request({ url: url, json: true }, (error, _, body) => error ? rej(error) : res(body))); + exports = module.exports; exports.extensionSwaggerSchemaUrl = "https://raw.githubusercontent.com/Azure/autorest/master/schema/swagger-extensions.json"; @@ -26,9 +27,9 @@ exports.isWindows = (process.platform.lastIndexOf('win') === 0); exports.prOnly = undefined !== process.env['PR_ONLY'] ? process.env['PR_ONLY'] : 'false'; exports.globPath = path.join(__dirname, '../', '../', '/specification/**/*.json'); -exports.swaggers = _(glob.sync(exports.globPath, { ignore: ['**/examples/**/*.json', '**/quickstart-templates/*.json', '**/schema/*.json'] })); +exports.swaggers = glob.sync(exports.globPath, { ignore: ['**/examples/**/*.json', '**/quickstart-templates/*.json', '**/schema/*.json'] }); exports.exampleGlobPath = path.join(__dirname, '../', '../', '/specification/**/examples/**/*.json'); -exports.examples = _(glob.sync(exports.exampleGlobPath)); +exports.examples = glob.sync(exports.exampleGlobPath); // Remove byte order marker. This catches EF BB BF (the UTF-8 BOM) // because the buffer-to-string conversion in `fs.readFile()` @@ -47,16 +48,13 @@ exports.stripBOM = function stripBOM(content) { * Parses the json from the given filepath * @returns {string} clr command */ -exports.parseJsonFromFile = function parseJsonFromFile(filepath, callback) { - fs.readFile(filepath, 'utf8', function (err, data) { - if (err) return callback(err); - try { - return callback(null, YAML.safeLoad(exports.stripBOM(data))); - } catch (error) { - let e = new Error(`swagger "${filepath}" is an invalid JSON.\n${util.inspect(error, { depth: null })}`); - return callback(e); - } - }); +exports.parseJsonFromFile = async function parseJsonFromFile(filepath) { + const data = await fs.readFile(filepath, { encoding: 'utf8' }); + try { + return YAML.safeLoad(exports.stripBOM(data)); + } catch (error) { + throw new Error(`swagger "${filepath}" is an invalid JSON.\n${util.inspect(error, { depth: null })}`); + } }; /** @@ -238,37 +236,17 @@ exports.getFilesChangedInPR = function getFilesChangedInPR() { * Downloads the remote schemas and initializes the validator with remote references. * @returns {Object} context Provides the schemas in json format and the validator. */ -exports.initializeValidator = function initializeValidator(callback) { - request({ url: exports.extensionSwaggerSchemaUrl, json: true }, function (error, response, extensionSwaggerSchemaBody) { - if (error) { - return callback(error); - } - request({ url: exports.swaggerSchemaAltUrl, json: true }, function (error, response, swaggerSchemaBody) { - if (error) { - return callback(error); - } - request({ url: exports.exampleSchemaUrl, json: true }, function (error, response, exampleSchemaBody) { - if (error) { - return callback(error); - } - request({ url: exports.compositeSchemaUrl, json: true }, function (error, response, compositeSchemaBody) { - if (error) { - return callback(error); - } - let context = { - extensionSwaggerSchema: extensionSwaggerSchemaBody, - swaggerSchema: swaggerSchemaBody, - exampleSchema: exampleSchemaBody, - compositeSchema: compositeSchemaBody - }; - let validator = new z({ breakOnFirstError: false }); - validator.setRemoteReference(exports.swaggerSchemaUrl, context.swaggerSchema); - validator.setRemoteReference(exports.exampleSchemaUrl, context.exampleSchema); - validator.setRemoteReference(exports.compositeSchemaUrl, context.compositeSchema); - context.validator = validator; - return callback(null, context); - }); - }); - }); - }); +exports.initializeValidator = async function initializeValidator() { + const context = { + extensionSwaggerSchema: await asyncJsonRequest(exports.extensionSwaggerSchemaUrl), + swaggerSchema: await asyncJsonRequest(exports.swaggerSchemaAltUrl), + exampleSchema: await asyncJsonRequest(exports.exampleSchemaUrl), + compositeSchema: await asyncJsonRequest(exports.compositeSchemaUrl) + }; + let validator = new z({ breakOnFirstError: false }); + validator.setRemoteReference(exports.swaggerSchemaUrl, context.swaggerSchema); + validator.setRemoteReference(exports.exampleSchemaUrl, context.exampleSchema); + validator.setRemoteReference(exports.compositeSchemaUrl, context.compositeSchema); + context.validator = validator; + return context; };