Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

openapi-to-postmanv2

Package Overview
Dependencies
Maintainers
8
Versions
172
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-to-postmanv2 - npm Package Compare versions

Comparing version 4.9.0 to 4.10.0

libV2/helpers/collection/generateAuthForCollectionFromOpenAPI.js

5

CHANGELOG.md
# OpenAPI-Postman Changelog
#### v4.10.0 (March 08, 2023)
* Added support for convertV2() interface which has more stacklimit for schema resolution.
* Added support for validateTransactionV2() interface uses same v2 interface for resolving schema.
* Fixed multiple issues for urlencoded body with anyOf and oneOf schemas where valid data was reported as mismatches.
#### v4.9.0 (February 06, 2023)

@@ -4,0 +9,0 @@ * Fixed issue [#660](https://github.com/postmanlabs/openapi-to-postman/issues/660) where for certain XML request bodies, conversion was failing with TypeError.

'use strict';
const { MODULE_VERSION } = require('./lib/schemapack.js');
const _ = require('lodash'),

@@ -17,2 +19,12 @@ SchemaPack = require('./lib/schemapack.js').SchemaPack;

convertV2: function(input, options, cb) {
var schema = new SchemaPack(input, options, MODULE_VERSION.V2);
if (schema.validated) {
return schema.convertV2(cb);
}
return cb(null, schema.validationResult);
},
validate: function (input) {

@@ -19,0 +31,0 @@ var schema = new SchemaPack(input);

58

lib/ajValidation/ajvValidation.js

@@ -54,2 +54,48 @@ const { formatDataPath,

/**
* Filter composite schema related mismatches.
*
* @param {*} schema - schema to validate
* @param {Array} validationMismatches - Array of standard AJV mismatches
* @returns {Array} Filtered mismatches after removing composite schema mismatches for valid data
*/
function filterCompositeSchemaErrors (schema, validationMismatches) {
_.forEach(['anyOf', 'oneOf'], (compositeSchemaKeyword) => {
const compositeSchemaMismatches = _.filter(validationMismatches, (validationMismatch) => {
return validationMismatch.keyword === compositeSchemaKeyword &&
_.endsWith(validationMismatch.schemaPath, compositeSchemaKeyword);
});
_.forEach(compositeSchemaMismatches, (compositeSchemaMismatch) => {
let compositeSchemaMismatchPath = compositeSchemaMismatch.schemaPath,
schemaDataPath = formatDataPath(formatSchemaPathFromAJVErrorToConvertToDataPath(compositeSchemaMismatchPath)),
schemaToUse = schemaDataPath ? _.get(schema, schemaDataPath) : schema,
isCompositeSchemaValid = false;
if (!_.isArray(schemaToUse)) {
return false;
}
for (let index = 0; index < schemaToUse.length; index++) {
const isCurrentElementInvalid = _.some(validationMismatches, (mismatch) => {
return _.startsWith(mismatch.schemaPath, compositeSchemaMismatchPath + `/${index}`);
});
if (!isCurrentElementInvalid) {
isCompositeSchemaValid = true;
break;
}
}
if (isCompositeSchemaValid) {
validationMismatches = _.reject(validationMismatches, (mismatch) => {
return _.startsWith(mismatch.schemaPath, compositeSchemaMismatchPath);
});
}
});
});
return validationMismatches;
}
/**
* Used to validate schema against a value.

@@ -104,3 +150,6 @@ * NOTE: Used in assets/json-schema-faker.js to validate schema example

if (validationError.keyword === 'type' || validationError.keyword === 'format') {
if (validationError.keyword === 'type' || validationError.keyword === 'format' ||
((validationError.keyword === 'minLength' || validationError.keyword === 'maxLength') &&
_.get(options, 'parametersResolution') === 'schema')
) {
let schemaDataPath = formatDataPath(formatSchemaPathFromAJVErrorToConvertToDataPath(validationError.schemaPath)),

@@ -115,2 +164,9 @@ schemaToUse = schemaDataPath ? _.get(schema, schemaDataPath) : schema,

/**
* AJV will provide mismatches for all elements of composite schema and as we consider
* a schema valid after filtering. Now even though one element is valid,
* AJV mismatches for other elements still remains. Such mismatches will be filtered here.
*/
filteredValidationError = filterCompositeSchemaErrors(schema, filteredValidationError);
// sort errors based on dataPath, as this will ensure no overriding later

@@ -117,0 +173,0 @@ filteredValidationError = _.sortBy(filteredValidationError, ['dataPath']);

14

lib/common/schemaUtilsCommon.js

@@ -256,3 +256,5 @@ /**

let initialDotIfExist = dataPath[0] === '/' ? '.' : '',
splittedDataPath = dataPath.split('/'),
// AJV returns encoded datapath in mismatches
decodedDataPath = decodeURIComponent(dataPath),
splittedDataPath = decodedDataPath.split('/'),
isANumber = (value) => {

@@ -322,4 +324,10 @@ return !isNaN(value);

formatSchemaPathFromAJVErrorToConvertToDataPath: function (schemaPath) {
return removeWordFromLastPosition(removeWordFromLastPosition(removeSharpAndSlashFromFirstPosition(schemaPath),
'type'), 'format');
let result = removeSharpAndSlashFromFirstPosition(schemaPath),
keywordsToRemoveFromPath = ['type', 'format', 'maxLength', 'minLength'];
_.forEach(keywordsToRemoveFromPath, (keyword) => {
result = removeWordFromLastPosition(result, keyword);
});
return result;
},

@@ -326,0 +334,0 @@

@@ -94,3 +94,3 @@ const _ = require('lodash'),

*
* @param {array} schemaArr REQUIRED - array of schemas, all of which must be valid in the returned object
* @param {*} schema REQUIRED - OpenAPI defined schema object to be resolved
* @param {string} parameterSourceOption REQUIRED tells that the schema object is of request or response

@@ -107,3 +107,3 @@ * @param {*} components REQUIRED components in openapi spec.

*/
resolveAllOf: function (schemaArr, parameterSourceOption, components, {
resolveAllOf: function (schema, parameterSourceOption, components, {
resolveFor = RESOLVE_REF_DEFAULTS.resolveFor,

@@ -117,19 +117,21 @@ resolveTo = RESOLVE_REF_DEFAULTS.resolveTo,

if (!(schemaArr instanceof Array)) {
if (_.isEmpty(schema)) {
return null;
}
if (schemaArr.length === 1) {
// for just one entry in allOf, don't need to enforce type: object restriction
return this.resolveRefs(schemaArr[0], parameterSourceOption, components,
{ stack, seenRef: _.cloneDeep(seenRef), resolveFor, resolveTo, stackLimit, analytics });
let resolvedNonAllOfSchema = {};
// Resolve schema excluding allOf keyword which will be further used to resolve entire schema along with allOf
if (_.keys(schema).length > 1) {
resolvedNonAllOfSchema = this.resolveRefs(_.omit(schema, 'allOf'), parameterSourceOption, components,
{ stack, seenRef: _.cloneDeep(seenRef), resolveFor, resolveTo, stackLimit, isAllOf: true, analytics });
}
try {
return mergeAllOf({
allOf: schemaArr.map((schema) => {
return mergeAllOf(_.assign(resolvedNonAllOfSchema, {
allOf: _.map(schema.allOf, (schema) => {
return this.resolveRefs(schema, parameterSourceOption, components,
{ stack, seenRef: _.cloneDeep(seenRef), resolveFor, resolveTo, stackLimit, isAllOf: true, analytics });
})
}, {
}), {
resolvers: {

@@ -252,3 +254,3 @@ // for keywords in OpenAPI schema that are not standard defined JSON schema keywords, use default resolver

if (schema.allOf) {
return this.resolveAllOf(schema.allOf, parameterSourceOption, components,
return this.resolveAllOf(schema, parameterSourceOption, components,
{

@@ -302,2 +304,5 @@ resolveFor,

if (resolvedSchema) {
if (schema.example) {
resolvedSchema.example = schema.example;
}
let refResolvedSchema = this.resolveRefs(resolvedSchema, parameterSourceOption,

@@ -435,3 +440,3 @@ components, {

if (schema.hasOwnProperty('type')) {
// Override default value to schema for CONVERSION only for parmeter resolution set to schema
// Override default value to schema for CONVERSION only for parameter resolution set to schema
if (resolveFor === 'CONVERSION' && resolveTo === 'schema') {

@@ -456,6 +461,23 @@ if (!schema.hasOwnProperty('format')) {

else if (schema.enum && schema.enum.length > 0) {
return {
type: (typeof (schema.enum[0])),
value: schema.enum[0]
};
if (resolveFor === 'CONVERSION' && resolveTo === 'schema') {
schema.type = (typeof (schema.enum[0]));
if (!schema.hasOwnProperty('format')) {
schema.default = '<' + schema.type + '>';
}
else if (typesMap.hasOwnProperty(schema.type)) {
schema.default = typesMap[schema.type][schema.format];
if (!schema.default && schema.format) {
schema.default = '<' + schema.format + '>';
}
}
else {
schema.default = '<' + schema.type + (schema.format ? ('-' + schema.format) : '') + '>';
}
}
else {
return {
type: (typeof (schema.enum[0])),
value: schema.enum[0]
};
}
}

@@ -462,0 +484,0 @@ else if (isAllOf) {

@@ -8,3 +8,7 @@ const { filterOptionsByVersion } = require('./common/versionUtils');

VERSION20 = '2.0',
SUPPORTED_VERSIONS = [VERSION20, VERSION30, VERSION31];
SUPPORTED_VERSIONS = [VERSION20, VERSION30, VERSION31],
MODULE_VERSION = {
V1: 'v1',
V2: 'v2'
};

@@ -71,3 +75,4 @@ /**

usage: ['CONVERSION', 'VALIDATION'],
supportedIn: [VERSION20, VERSION30, VERSION31]
supportedIn: [VERSION20, VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
},

@@ -83,3 +88,4 @@ {

usage: ['CONVERSION'],
supportedIn: [VERSION20, VERSION30, VERSION31]
supportedIn: [VERSION20, VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
},

@@ -95,3 +101,4 @@ {

usage: ['CONVERSION'],
supportedIn: [VERSION20, VERSION30, VERSION31]
supportedIn: [VERSION20, VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V1]
},

@@ -107,3 +114,4 @@ {

usage: ['CONVERSION'],
supportedIn: [VERSION20, VERSION30, VERSION31]
supportedIn: [VERSION20, VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V1]
},

@@ -122,3 +130,4 @@ {

usage: ['CONVERSION'],
supportedIn: [VERSION20, VERSION30, VERSION31]
supportedIn: [VERSION20, VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V1]
},

@@ -137,5 +146,32 @@ {

usage: ['CONVERSION'],
supportedIn: [VERSION20, VERSION30, VERSION31]
supportedIn: [VERSION20, VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V1]
},
{
name: 'Disabled Parameter validation',
id: 'disabledParametersValidation',
type: 'boolean',
default: true,
description: 'Whether disabled parameters of collection should be validated',
external: false,
usage: ['VALIDATION'],
supportedIn: [VERSION20, VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
},
{
name: 'Parameter generation',
id: 'parametersResolution',
type: 'enum',
default: 'Schema',
availableOptions: ['Example', 'Schema'],
description: 'Select whether to generate the request and response parameters based on the' +
' [schema](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schemaObject) or the' +
' [example](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#exampleObject)' +
' in the schema.',
external: true,
usage: ['CONVERSION'],
supportedIn: [VERSION20, VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
},
{
name: 'Folder organization',

@@ -149,3 +185,4 @@ id: 'folderStrategy',

usage: ['CONVERSION'],
supportedIn: [VERSION20, VERSION30, VERSION31]
supportedIn: [VERSION20, VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
},

@@ -160,3 +197,4 @@ {

usage: ['CONVERSION'],
supportedIn: [VERSION20, VERSION30, VERSION31]
supportedIn: [VERSION20, VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
},

@@ -173,3 +211,4 @@ {

usage: ['CONVERSION'],
supportedIn: [VERSION20, VERSION30, VERSION31]
supportedIn: [VERSION20, VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
},

@@ -184,3 +223,4 @@ {

usage: ['CONVERSION'],
supportedIn: [VERSION20, VERSION30, VERSION31]
supportedIn: [VERSION20, VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
},

@@ -195,3 +235,4 @@ {

usage: ['VALIDATION'],
supportedIn: [VERSION30, VERSION31]
supportedIn: [VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
},

@@ -208,3 +249,4 @@ {

usage: ['VALIDATION'],
supportedIn: [VERSION30, VERSION31]
supportedIn: [VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
},

@@ -220,3 +262,4 @@ {

usage: ['VALIDATION'],
supportedIn: [VERSION30, VERSION31]
supportedIn: [VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
},

@@ -232,3 +275,4 @@ {

usage: ['VALIDATION'],
supportedIn: [VERSION30, VERSION31]
supportedIn: [VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
},

@@ -243,3 +287,4 @@ {

usage: ['VALIDATION'],
supportedIn: [VERSION30, VERSION31]
supportedIn: [VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
},

@@ -254,3 +299,4 @@ {

usage: ['VALIDATION'],
supportedIn: [VERSION30, VERSION31]
supportedIn: [VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
},

@@ -265,3 +311,4 @@ {

usage: ['VALIDATION'],
supportedIn: [VERSION30, VERSION31]
supportedIn: [VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
},

@@ -277,3 +324,4 @@ {

usage: ['VALIDATION'],
supportedIn: [VERSION30, VERSION31]
supportedIn: [VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
},

@@ -289,3 +337,4 @@ {

supportedIn: [VERSION30, VERSION31],
usage: ['VALIDATION']
usage: ['VALIDATION'],
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
},

@@ -301,3 +350,4 @@ {

usage: ['CONVERSION'],
supportedIn: [VERSION20, VERSION30, VERSION31]
supportedIn: [VERSION20, VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V1]
},

@@ -312,3 +362,4 @@ {

usage: ['CONVERSION'],
supportedIn: [VERSION20, VERSION30, VERSION31]
supportedIn: [VERSION20, VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
},

@@ -323,3 +374,4 @@ {

usage: ['CONVERSION'],
supportedIn: [VERSION31]
supportedIn: [VERSION31],
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
},

@@ -334,3 +386,4 @@ {

usage: ['BUNDLE'],
supportedIn: [VERSION20, VERSION30, VERSION31]
supportedIn: [VERSION20, VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
},

@@ -346,3 +399,4 @@ {

usage: ['CONVERSION', 'VALIDATION'],
supportedIn: [VERSION20, VERSION30, VERSION31]
supportedIn: [VERSION20, VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
}

@@ -364,2 +418,13 @@ ];

}
if (_.has(criteria, 'moduleVersion')) {
optsArray = _.filter(optsArray, (option) => {
return _.includes(option.supportedModuleVersion, criteria.moduleVersion);
});
}
else {
optsArray = _.filter(optsArray, (option) => {
return _.includes(option.supportedModuleVersion, MODULE_VERSION.V1);
});
}
}

@@ -366,0 +431,0 @@

@@ -36,3 +36,5 @@ var yaml = require('js-yaml'),

try {
let obj = yaml.safeLoad(spec);
let obj = yaml.safeLoad(spec, {
schema: yaml.JSON_SCHEMA
});
// yaml.safeLoad does not throw errors for most of the cases in invalid yaml

@@ -39,0 +41,0 @@ // hence check if it returned an object

@@ -29,3 +29,8 @@ 'use strict';

schemaUtils = require('./schemaUtils'),
{ getServersPathVars } = require('./common/schemaUtilsCommon.js');
v2 = require('../libV2/index'),
{ getServersPathVars } = require('./common/schemaUtilsCommon.js'),
MODULE_VERSION = {
V1: 'v1',
V2: 'v2'
};

@@ -37,3 +42,3 @@ let path = require('path'),

class SchemaPack {
constructor (input, options = {}) {
constructor (input, options = {}, moduleVersion = MODULE_VERSION.V1) {
if (input.type === schemaUtils.MULTI_FILE_API_TYPE_ALLOWED_VALUE &&

@@ -47,3 +52,5 @@ input.data && input.data[0] && input.data[0].path) {

this.validationResult = null;
this.definedOptions = getOptions();
this.definedOptions = getOptions({
moduleVersion
});
this.computedOptions = null;

@@ -78,2 +85,22 @@ this.schemaFakerCache = {};

convertV2 (callback) {
if (!this.validated) {
return callback(new OpenApiErr('The schema must be validated before attempting conversion'));
}
// We only convert if swagger is found otherwise this.openapi remains the same
return convertToOAS30IfSwagger(getConcreteSchemaUtils(this.input), this.openapi, (error, convertedOpenAPI) => {
if (error) {
return callback(error);
}
this.openapi = convertedOpenAPI;
this.concreteUtils = concreteUtils;
this.specComponents = concreteUtils.getRequiredData(this.openapi);
v2.convertV2(this, callback);
});
}
// need to store the schema here

@@ -646,2 +673,21 @@ validate() {

/**
*
* @description Takes in a transaction object (meant to represent a Postman history object)
*
* @param {*} transactions RequestList
* @param {*} callback return
* @returns {boolean} validation
*/
validateTransactionV2(transactions, callback) {
if (!this.validated) {
return callback(new OpenApiErr('The schema must be validated before attempting conversion'));
}
this.concreteUtils = concreteUtils;
this.specComponents = concreteUtils.getRequiredData(this.openapi);
return v2.validateTransactionV2(this, transactions, callback);
}
static getOptions(mode, criteria) {

@@ -767,3 +813,4 @@ return getOptions(mode, criteria);

module.exports = {
SchemaPack
SchemaPack,
MODULE_VERSION
};

@@ -9,2 +9,4 @@ id|type|available options|default|description|usage

exampleParametersResolution|enum|Example, Schema|Example|Select whether to generate the response parameters based on the [schema](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schemaObject) or the [example](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#exampleObject) in the schema.|CONVERSION
disabledParametersValidation|boolean|-|true|Whether disabled parameters of collection should be validated|VALIDATION
parametersResolution|enum|Example, Schema|Schema|Select whether to generate the request and response parameters based on the [schema](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schemaObject) or the [example](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#exampleObject) in the schema.|CONVERSION
folderStrategy|enum|Paths, Tags|Paths|Select whether to create folders according to the spec’s paths or tags.|CONVERSION

@@ -11,0 +13,0 @@ schemaFaker|boolean|-|true|Whether or not schemas should be faked.|CONVERSION

{
"name": "openapi-to-postmanv2",
"version": "4.9.0",
"version": "4.10.0",
"description": "Convert a given OpenAPI specification to Postman Collection v2.0",

@@ -128,2 +128,3 @@ "homepage": "https://github.com/postmanlabs/openapi-to-postman",

"object-hash": "3.0.0",
"graphlib": "2.1.8",
"path-browserify": "1.0.1",

@@ -151,3 +152,3 @@ "postman-collection": "4.1.5",

"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 +155,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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc