openapi-to-postmanv2
Advanced tools
Comparing version 4.9.0-beta.14 to 4.9.0-beta.15
@@ -147,3 +147,3 @@ const { filterOptionsByVersion } = require('./common/versionUtils'); | ||
type: 'boolean', | ||
default: false, | ||
default: true, | ||
description: 'Whether disabled parameters of collection should be validated', | ||
@@ -150,0 +150,0 @@ external: false, |
@@ -678,4 +678,2 @@ 'use strict'; | ||
validateTransactionV2(transactions, callback) { | ||
let componentsAndPaths; | ||
if (!this.validated) { | ||
@@ -685,13 +683,6 @@ return callback(new OpenApiErr('The schema must be validated before attempting conversion')); | ||
// this cannot be attempted before validation | ||
componentsAndPaths = { concreteUtils }; | ||
Object.assign(componentsAndPaths, concreteUtils.getRequiredData(this.openapi)); | ||
this.concreteUtils = concreteUtils; | ||
this.specComponents = concreteUtils.getRequiredData(this.openapi); | ||
return v2.validateTransactionV2({ | ||
schema: this.openapi, | ||
options: this.computedOptions, | ||
transactions: transactions, | ||
componentsAndPaths: componentsAndPaths, | ||
schemaCache: this.schemaFakerCache | ||
}, callback); | ||
return v2.validateTransactionV2(this, transactions, callback); | ||
} | ||
@@ -698,0 +689,0 @@ |
@@ -5,3 +5,3 @@ /* eslint-disable one-var */ | ||
GraphLib = require('graphlib'), | ||
generateSkeletonTreeFromOpenAPI = require('./helpers/collection/generateSkeletionTreeeFromOpenAPI'), | ||
generateSkeletonTreeFromOpenAPI = require('./helpers/collection/generateSkeletionTreeFromOpenAPI'), | ||
generateCollectionFromOpenAPI = require('./helpers/collection/generateCollectionFromOpenAPI'), | ||
@@ -233,9 +233,18 @@ generateFolderFromOpenAPI = require('./helpers/folder/generateFolderForOpenAPI'), | ||
* @param {Object} context - Required context from related SchemaPack function | ||
* @param {Array} transactions - Transactions to be validated | ||
* @param {*} callback return | ||
* @returns {boolean} validation | ||
*/ | ||
validateTransactionV2(context, callback) { | ||
let { schema, options, transactions, componentsAndPaths, schemaCache } = context, | ||
validateTransactionV2(context, transactions, callback) { | ||
let schema = context.openapi, | ||
options = context.computedOptions, | ||
concreteUtils = context.concreteUtils, | ||
componentsAndPaths = { concreteUtils }, | ||
schemaCache = context.schemaFakerCache, | ||
matchedEndpoints = []; | ||
context.schemaCache = context.schemaCache || {}; | ||
context.schemaFakerCache = context.schemaFakerCache || {}; | ||
Object.assign(componentsAndPaths, concreteUtils.getRequiredData(schema)); | ||
// create and sanitize basic spec | ||
@@ -274,3 +283,3 @@ schema.servers = _.isEmpty(schema.servers) ? [{ url: '/' }] : schema.servers; | ||
async.map(transactions, (transaction, callback) => { | ||
return validateTransaction(transaction, { | ||
return validateTransaction(context, transaction, { | ||
schema, options, componentsAndPaths, schemaCache, matchedEndpoints | ||
@@ -300,3 +309,3 @@ }, callback); | ||
requests: _.keyBy(result, 'requestId'), | ||
missingEndpoints: getMissingSchemaEndpoints(schema, matchedEndpoints, | ||
missingEndpoints: getMissingSchemaEndpoints(context, schema, matchedEndpoints, | ||
componentsAndPaths, options, schemaCache) | ||
@@ -303,0 +312,0 @@ }; |
@@ -389,3 +389,4 @@ const _ = require('lodash'); | ||
getPostmanUrlSuffixSchemaScore, | ||
isPmVariable | ||
}; |
@@ -67,3 +67,3 @@ const generateAuthForCollectionFromOpenAPI = require('./helpers/collection/generateAuthForCollectionFromOpenAPI'); | ||
if (!bodyContent.match(regExp)) { | ||
if (_.isFunction(bodyContent.match) && !bodyContent.match(regExp)) { | ||
const versionContent = '<?xml version="1.0" encoding="UTF-8"?>\n'; | ||
@@ -207,3 +207,6 @@ xmlBody = versionContent + xmlBody; | ||
* @param {Number} stackDepth - Depth of the current stack for Ref resolution | ||
* @param {*} resolveFor - resolve refs for flow validation/conversion (value to be one of VALIDATION/CONVERSION) | ||
* @param {Object} seenRef - Seen Reference map | ||
* @param {string} resolveTo The desired JSON-generation mechanism (schema: prefer using the JSONschema to | ||
generate a fake object, example: use specified examples as-is). Default: schema | ||
* | ||
@@ -403,2 +406,4 @@ * @returns {Object} Returns the object that staisfies the schema | ||
* @param {Object} schema - Schema to be resolved | ||
* @param {Number} [stack] - Current recursion depth | ||
* @param {*} resolveFor - resolve refs for flow validation/conversion (value to be one of VALIDATION/CONVERSION) | ||
* @param {Object} seenRef - Map of all the references that have been resolved | ||
@@ -556,2 +561,3 @@ * | ||
* | ||
* @param {Object} context - Required context from related SchemaPack function | ||
* @param {Object} param - OpenAPI Parameter object | ||
@@ -690,3 +696,5 @@ * @returns {Object} - Information regarding parameter serialisation. Contains following properties. | ||
* | ||
* @param {Object} context - Required context from related SchemaPack function | ||
* @param {Object} param - Parameter that is to be resolved from schema | ||
* @param {String} schemaFormat - Corresponding schema format (can be one of xml/default) | ||
* @returns {*} Value of the parameter | ||
@@ -1272,2 +1280,9 @@ */ | ||
if (!_.isObject(requestContent)) { | ||
return { | ||
body: '', | ||
headers: [] | ||
}; | ||
} | ||
if (requestContent[URLENCODED]) { | ||
@@ -1284,4 +1299,53 @@ return resolveUrlEncodedRequestBodyForPostmanRequest(context, requestContent[URLENCODED]); | ||
resolvePathItemParams = (context, operationParam, pathParam) => { | ||
if (!Array.isArray(operationParam)) { | ||
operationParam = []; | ||
} | ||
if (!Array.isArray(pathParam)) { | ||
pathParam = []; | ||
} | ||
pathParam.forEach((param, index, arr) => { | ||
if (_.has(param, '$ref')) { | ||
arr[index] = resolveRefFromSchema(context, param.$ref); | ||
} | ||
}); | ||
operationParam.forEach((param, index, arr) => { | ||
if (_.has(param, '$ref')) { | ||
arr[index] = resolveRefFromSchema(context, param.$ref); | ||
} | ||
}); | ||
if (_.isEmpty(pathParam)) { | ||
return operationParam; | ||
} | ||
else if (_.isEmpty(operationParam)) { | ||
return pathParam; | ||
} | ||
// If both path and operation params exist, | ||
// we need to de-duplicate | ||
// A param with the same name and 'in' value from operationParam | ||
// will get precedence | ||
var reqParam = operationParam.slice(); | ||
pathParam.forEach((param) => { | ||
var dupParam = operationParam.find(function(element) { | ||
return element.name === param.name && element.in === param.in && | ||
// the below two conditions because undefined === undefined returns true | ||
element.name && param.name && | ||
element.in && param.in; | ||
}); | ||
if (!dupParam) { | ||
// if there's no duplicate param in operationParam, | ||
// use the one from the common pathParam list | ||
// this ensures that operationParam is given precedence | ||
reqParam.push(param); | ||
} | ||
}); | ||
return reqParam; | ||
}, | ||
resolveQueryParamsForPostmanRequest = (context, operationItem, method) => { | ||
const params = operationItem.parameters || operationItem[method].parameters, | ||
const params = resolvePathItemParams(context, operationItem[method].parameters, operationItem.parameters), | ||
pmParams = []; | ||
@@ -1317,3 +1381,3 @@ | ||
resolvePathParamsForPostmanRequest = (context, operationItem, method) => { | ||
const params = operationItem.parameters || operationItem[method].parameters, | ||
const params = resolvePathItemParams(context, operationItem[method].parameters, operationItem.parameters), | ||
pmParams = []; | ||
@@ -1374,3 +1438,3 @@ | ||
resolveHeadersForPostmanRequest = (context, operationItem, method) => { | ||
const params = operationItem.parameters || operationItem[method].parameters, | ||
const params = resolvePathItemParams(context, operationItem[method].parameters, operationItem.parameters), | ||
pmParams = [], | ||
@@ -1377,0 +1441,0 @@ { keepImplicitHeaders } = context.computedOptions; |
@@ -80,2 +80,7 @@ const sdk = require('postman-collection'), | ||
/** | ||
* Following is added to make sure body pruning for request methods like GET, HEAD etc is disabled'. | ||
* https://github.com/postmanlabs/postman-runtime/blob/develop/docs/protocol-profile-behavior.md | ||
*/ | ||
requestItem.protocolProfileBehavior = { disableBodyPruning: true }; | ||
@@ -82,0 +87,0 @@ return requestItem.toJSON(); |
{ | ||
"name": "openapi-to-postmanv2", | ||
"version": "4.9.0-beta.14", | ||
"version": "4.9.0-beta.15", | ||
"description": "Convert a given OpenAPI specification to Postman Collection v2.0", | ||
@@ -151,3 +151,3 @@ "homepage": "https://github.com/postmanlabs/openapi-to-postman", | ||
"test": "./scripts/test.sh", | ||
"test-unit": "nyc --reporter=text -x **/assets/** -x **/test/** ./node_modules/mocha/bin/mocha \"test/unit/**/**.test.js\"", | ||
"test-unit": "nyc --reporter=text -x **/assets/** -x **/test/** ./node_modules/mocha/bin/mocha --timeout 90000 \"test/unit/**/**.test.js\"", | ||
"test-lint": "./scripts/test-lint.sh", | ||
@@ -154,0 +154,0 @@ "test-system": "./node_modules/mocha/bin/mocha -x **/assets/** -x **/test/** \"test/system/**.test.js\"", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1694592
43465