Adding usage guide for validator API

This commit is contained in:
Abhijit Kane
2019-12-18 12:10:49 +05:30
parent 18e00de729
commit 56075c044d
2 changed files with 19 additions and 9 deletions

View File

@@ -221,7 +221,6 @@ class SchemaPack {
* @description Takes in a transaction object (meant to represent a Postman history object)
*
* @param {*} transactions RequestList
* @param {*} options Validation-specific options, optional
* @param {*} callback return
* @returns {boolean} validation
*/
@@ -239,8 +238,7 @@ class SchemaPack {
async.map(transactions, (transaction, requestCallback) => {
// 1. Look at transaction.request.URL, and find matching request from schema
console.log('Starting checks for txn' + transaction.id);
// 1. Look at transaction.request.URL + method, and find matching request from schema
let matchedPaths = schemaUtils.findMatchingRequestFromSchema(
transaction.request.method,
transaction.request.url, // must be a string
@@ -248,13 +246,12 @@ class SchemaPack {
);
if (!matchedPaths.length) {
console.log('No matched paths found');
// No matching paths found
return requestCallback(null, []);
}
// 2. perform validation for each identified matchedPath (schema endpoint)
async.map(matchedPaths, (matchedPath, pathsCallback) => {
console.log('Starting validation for txn ' + transaction.id + ' for path ' + matchedPath.name);
return async.map(matchedPaths, (matchedPath, pathsCallback) => {
// 3. validation involves checking these individual properties
async.parallel({
path: function(cb) {
@@ -274,7 +271,6 @@ class SchemaPack {
matchedPath.path, componentsAndPaths, options, cb);
}
}, (err, result) => {
console.log('Checked all properties for txn ' + transaction.id + ' for path ' + matchedPath.name);
let allMismatches = _.concat(result.headers, result.path, result.requestBody),
retVal = { matched: true }; // no mismatch
@@ -286,9 +282,7 @@ class SchemaPack {
}
pathsCallback(null, retVal);
});
}, (err, result) => {
console.log('Checked all matchedPaths for txn ' + transaction.id);
requestCallback(err, {
requestId: transaction.id,
endpoints: result

16
validator_perf.js Normal file
View File

@@ -0,0 +1,16 @@
/* eslint-disable */
var Converter = require('./index.js'),
fs = require('fs'),
path = require('path'),
VALID_OPENAPI_PATH = './test/data/.temp/specs/spec-to-validate-against.json',
HISTORY_PATH = './test/data/.temp/specs/history_obj.json';
var openapi = JSON.parse(fs.readFileSync(path.join(__dirname, VALID_OPENAPI_PATH), 'utf8')),
historyRequest = JSON.parse(fs.readFileSync(path.join(__dirname, HISTORY_PATH), 'utf8'));
let schemaPack = new Converter.SchemaPack({ type: 'json', data: openapi }, {});
schemaPack.validateTransaction(historyRequest, (err, result) => {
// result is as described in the Schema <> Validation Doc
});