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.13.0 to 4.14.0

15

CHANGELOG.md

@@ -5,2 +5,13 @@ # OpenAPI-Postman Changelog

## [v4.14.0] - 2023-06-07
### Added
- Added support for consumption of schema level examples while generating data from XML schemas.
### Fixed
- Fixed the default value of auth in the generated request when it is not resolved.
- Fixed issue where collection name was empty in cases where definition title was defined as empty string.
## [v4.13.0] - 2023-05-24

@@ -566,4 +577,6 @@

[Unreleased]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.13.0...HEAD
[Unreleased]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.14.0...HEAD
[v4.14.0]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.13.0...v4.14.0
[v4.13.0]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.12.0...v4.13.0

@@ -570,0 +583,0 @@

@@ -377,2 +377,14 @@ const { filterOptionsByVersion } = require('./common/versionUtils');

supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
},
{
name: 'Always inherit authentication',
id: 'alwaysInheritAuthentication',
type: 'boolean',
default: false,
description: 'Whether authentication details should be included on every request, or always inherited from ' +
'the collection.',
external: true,
usage: ['CONVERSION'],
supportedIn: [VERSION20, VERSION30, VERSION31],
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
}

@@ -379,0 +391,0 @@ ];

18

lib/schemapack.js
'use strict';
// This is the default collection name if one can't be inferred from the OpenAPI spec
const COLLECTION_NAME = 'Imported from OpenAPI 3.0',
{ getConcreteSchemaUtils } = require('./common/versionUtils.js'),
const { getConcreteSchemaUtils } = require('./common/versionUtils.js'),
{ convertToOAS30IfSwagger } = require('./swaggerUtils/swaggerToOpenapi.js'),

@@ -197,8 +195,10 @@ BROWSER = 'browser',

else if (this.validated) {
let name = utils.getCollectionName(_.get(this.openapi, 'info.title'));
return cb(null, {
result: true,
name: _.get(this.openapi, 'info.title', COLLECTION_NAME),
name: name,
output: [{
type: 'collection',
name: _.get(this.openapi, 'info.title', COLLECTION_NAME)
name: name
}]

@@ -217,8 +217,10 @@ });

let name = utils.getCollectionName(_.get(this.openapi, 'info.title'));
return cb(null, {
result: true,
name: _.get(this.openapi, 'info.title', COLLECTION_NAME),
name: name,
output: [{
type: 'collection',
name: _.get(this.openapi, 'info.title', COLLECTION_NAME)
name: name
}]

@@ -345,3 +347,3 @@ });

info: {
name: _.isEmpty(_.get(openapi, 'info.title')) ? COLLECTION_NAME : _.get(openapi, 'info.title')
name: utils.getCollectionName(_.get(openapi, 'info.title'))
}

@@ -348,0 +350,0 @@ });

@@ -1,3 +0,6 @@

const _ = require('lodash');
const _ = require('lodash'),
// This is the default collection name if one can't be inferred from the OpenAPI spec
COLLECTION_NAME = 'Imported from OpenAPI';
// this will have non-OAS-related utils

@@ -145,3 +148,17 @@

return res.join('/');
},
/**
* Provides collection name to be used for generated collection
*
* @param {*} title - Definition title
* @returns {String} - Collection name
*/
getCollectionName: function (title) {
if (_.isEmpty(title) || !_.isString(title)) {
return COLLECTION_NAME;
}
return title;
}
};
/* eslint-disable */
const _ = require('lodash');
const _ = require('lodash'),
js2xml = require('../lib/common/js2xml');
function convertSchemaToXML(name, schema, attribute, indentChar, indent) {
function indentContent (content, initialIndent) {
let contentArr = _.split(content, '\n'),
indentedContent = _.join(_.map(contentArr, (contentElement) => { return initialIndent + contentElement; }), '\n');
return indentedContent;
}
function convertSchemaToXML(name, schema, attribute, indentChar, indent, resolveTo) {
var tagPrefix = '',
cIndent = _.times(indent, _.constant(indentChar)).join('');
cIndent = _.times(indent, _.constant(indentChar)).join(''),
retVal = '';
const schemaExample = typeof schema === 'object' && (schema.example);
name = _.get(schema, 'xml.name', name || 'element');

@@ -24,2 +36,7 @@ if (_.get(schema, 'xml.prefix')) {

}
if (resolveTo === 'example' && typeof schemaExample !== 'undefined') {
actualValue = schemaExample;
}
if (attribute) {

@@ -29,3 +46,3 @@ return actualValue;

else {
var retVal = `\n${cIndent}<${tagPrefix+name}`;
retVal = `\n${cIndent}<${tagPrefix+name}`;
if (_.get(schema, 'xml.namespace')) {

@@ -38,25 +55,36 @@ retVal += ` xmlns:${tagPrefix.slice(0,-1)}="${schema.xml.namespace}"`

else if (schema.type === 'object') {
// go through all properties
var retVal = '\n' + cIndent + `<${tagPrefix}${name}`, propVal, attributes = [], childNodes = '';
if (_.get(schema, 'xml.namespace')) {
let formattedTagPrefix = tagPrefix ?
`:${tagPrefix.slice(0,-1)}` :
'';
retVal += ` xmlns${formattedTagPrefix}="${schema.xml.namespace}"`
if (resolveTo === 'example' && typeof schemaExample !== 'undefined') {
const elementName = _.get(schema, 'items.xml.name', name || 'element'),
fakedContent = js2xml({ [elementName]: schemaExample }, indentChar);
retVal = '\n' + indentContent(fakedContent, cIndent);
}
_.forOwn(schema.properties, (value, key) => {
propVal = convertSchemaToXML(key, value, _.get(value, 'xml.attribute'), indentChar, indent + 1);
if (_.get(value, 'xml.attribute')) {
attributes.push(`${key}="${propVal}"`);
else {
// go through all properties
var propVal, attributes = [], childNodes = '';
retVal = '\n' + cIndent + `<${tagPrefix}${name}`;
if (_.get(schema, 'xml.namespace')) {
let formattedTagPrefix = tagPrefix ?
`:${tagPrefix.slice(0,-1)}` :
'';
retVal += ` xmlns${formattedTagPrefix}="${schema.xml.namespace}"`
}
else {
childNodes += _.isString(propVal) ? propVal : '';
_.forOwn(schema.properties, (value, key) => {
propVal = convertSchemaToXML(key, value, _.get(value, 'xml.attribute'), indentChar, indent + 1, resolveTo);
if (_.get(value, 'xml.attribute')) {
attributes.push(`${key}="${propVal}"`);
}
else {
childNodes += _.isString(propVal) ? propVal : '';
}
});
if (attributes.length > 0) {
retVal += ' ' + attributes.join(' ');
}
});
if (attributes.length > 0) {
retVal += ' ' + attributes.join(' ');
retVal += '>';
retVal += childNodes;
retVal += `\n${cIndent}</${tagPrefix}${name}>`;
}
retVal += '>';
retVal += childNodes;
retVal += `\n${cIndent}</${tagPrefix}${name}>`;
}

@@ -67,3 +95,3 @@ else if (schema.type === 'array') {

extraIndent = isWrapped ? 1 : 0,
arrayElemName = _.get(schema, 'items.xml.name', name, 'arrayItem'),
arrayElemName = _.get(schema, 'items.xml.name', name || 'element'),
schemaItemsWithXmlProps = _.cloneDeep(schema.items),

@@ -73,4 +101,16 @@ contents;

schemaItemsWithXmlProps.xml = schema.xml;
contents = convertSchemaToXML(arrayElemName, schemaItemsWithXmlProps, false, indentChar, indent + extraIndent) +
convertSchemaToXML(arrayElemName, schemaItemsWithXmlProps, false, indentChar, indent + extraIndent);
if (resolveTo === 'example' && typeof schemaExample !== 'undefined') {
const fakedContent = js2xml({ [arrayElemName]: schemaExample }, indentChar);
contents = '\n' + indentContent(fakedContent, cIndent);
}
else {
let singleElementContent = convertSchemaToXML(arrayElemName, schemaItemsWithXmlProps, false, indentChar,
indent + extraIndent, resolveTo);
// Atleast 2 items per array will be added asame as JSON schema faker
contents = singleElementContent + singleElementContent;
}
if (isWrapped) {

@@ -86,5 +126,5 @@ return `\n${cIndent}<${tagPrefix}${name}>${contents}\n${cIndent}</${tagPrefix}${name}>`;

module.exports = function(name, schema, indentCharacter) {
module.exports = function(name, schema, indentCharacter, resolveTo) {
// substring(1) to trim the leading newline
return convertSchemaToXML(name, schema, false, indentCharacter, 0).substring(1);
return convertSchemaToXML(name, schema, false, indentCharacter, 0, resolveTo).substring(1);
};

@@ -91,0 +131,0 @@ /*

const _ = require('lodash'),
utils = require('../../utils'),
generateAuthrForCollectionFromOpenAPI = require('./generateAuthForCollectionFromOpenAPI'),
COLLECTION_NAME = 'Imported from OpenAPI 3.0',

@@ -99,3 +99,3 @@ /**

info: {
name: _.get(openapi, 'info.title', COLLECTION_NAME),
name: utils.getCollectionName(_.get(openapi, 'info.title')),
description: getCollectionDescription(openapi)

@@ -102,0 +102,0 @@ },

@@ -8,3 +8,2 @@ const generateAuthForCollectionFromOpenAPI = require('./helpers/collection/generateAuthForCollectionFromOpenAPI');

xmlFaker = require('./xmlSchemaFaker.js'),
js2xml = require('../lib/common/js2xml'),
URLENCODED = 'application/x-www-form-urlencoded',

@@ -866,3 +865,3 @@ APP_JSON = 'application/json',

if (schemaFormat === SCHEMA_FORMATS.XML) {
return xmlFaker(null, resolvedSchema, indentCharacter);
return xmlFaker(null, resolvedSchema, indentCharacter, parametersResolution);
}

@@ -1148,3 +1147,10 @@

if (bodyType === APP_XML || bodyType === TEXT_XML || headerFamily === HEADER_TYPE.XML) {
bodyData = js2xml(exampleData, indentCharacter);
let reqBodySchemaWithExample = requestBodySchema;
// Assign example at schema level to be faked by xmlSchemaFaker
if (typeof requestBodySchema === 'object') {
reqBodySchemaWithExample = Object.assign({}, requestBodySchema, { example: exampleData });
}
return xmlFaker(null, reqBodySchemaWithExample, indentCharacter, parametersResolution);
}

@@ -1163,3 +1169,3 @@ else {

if (bodyType === APP_XML || bodyType === TEXT_XML || headerFamily === HEADER_TYPE.XML) {
return xmlFaker(null, requestBodySchema, indentCharacter);
return xmlFaker(null, requestBodySchema, indentCharacter, parametersResolution);
}

@@ -1873,3 +1879,4 @@

securitySchema = _.get(operationItem, [method, 'security']),
authHelper = generateAuthForCollectionFromOpenAPI(context.openapi, securitySchema);
authHelper = generateAuthForCollectionFromOpenAPI(context.openapi, securitySchema),
{ alwaysInheritAuthentication } = context.computedOptions;

@@ -1893,3 +1900,3 @@ headers.push(..._.get(requestBody, 'headers', []));

body: _.get(requestBody, 'body'),
auth: authHelper
auth: alwaysInheritAuthentication ? undefined : authHelper
};

@@ -1896,0 +1903,0 @@

const sdk = require('postman-collection'),
_ = require('lodash'),
// This is the default collection name if one can't be inferred from the OpenAPI spec
COLLECTION_NAME = 'Imported from OpenAPI',
generatePmResponseObject = (response) => {

@@ -55,3 +58,3 @@ const requestItem = generateRequestItemObject({ // eslint-disable-line no-use-before-define

responses = _.get(requestObject, 'request.responses', []),
auth = _.get(requestObject, 'request.auth', []);
auth = _.get(requestObject, 'request.auth', null);

@@ -186,4 +189,18 @@ _.forEach(queryParams, (param) => {

/**
* Provides collection name to be used for generated collection
*
* @param {*} title - Definition title
* @returns {String} - Collection name
*/
getCollectionName: function (title) {
if (_.isEmpty(title) || !_.isString(title)) {
return COLLECTION_NAME;
}
return title;
},
generatePmResponseObject,
generateRequestItemObject
};
/* eslint-disable */
const _ = require('lodash');
const _ = require('lodash'),
js2xml = require('../lib/common/js2xml');
function convertSchemaToXML(name, schema, attribute, indentChar, indent) {
function indentContent (content, initialIndent) {
let contentArr = _.split(content, '\n'),
indentedContent = _.join(_.map(contentArr, (contentElement) => { return initialIndent + contentElement; }), '\n');
return indentedContent;
}
function convertSchemaToXML(name, schema, attribute, indentChar, indent, resolveTo) {
var tagPrefix = '',

@@ -9,2 +17,4 @@ cIndent = _.times(indent, _.constant(indentChar)).join(''),

const schemaExample = typeof schema === 'object' && (schema.example);
name = _.get(schema, 'xml.name', name || 'element');

@@ -27,2 +37,7 @@ if (_.get(schema, 'xml.prefix')) {

}
if (resolveTo === 'example' && typeof schemaExample !== 'undefined') {
actualValue = schemaExample;
}
if (attribute) {

@@ -32,3 +47,3 @@ return actualValue;

else {
var retVal = `\n${cIndent}<${tagPrefix+name}`;
retVal = `\n${cIndent}<${tagPrefix+name}`;
if (_.get(schema, 'xml.namespace')) {

@@ -41,25 +56,36 @@ retVal += ` xmlns:${tagPrefix.slice(0,-1)}="${schema.xml.namespace}"`

else if (schema.type === 'object') {
// go through all properties
var retVal = '\n' + cIndent + `<${tagPrefix}${name}`, propVal, attributes = [], childNodes = '';
if (_.get(schema, 'xml.namespace')) {
let formattedTagPrefix = tagPrefix ?
`:${tagPrefix.slice(0,-1)}` :
'';
retVal += ` xmlns${formattedTagPrefix}="${schema.xml.namespace}"`
if (resolveTo === 'example' && typeof schemaExample !== 'undefined') {
const elementName = _.get(schema, 'items.xml.name', name || 'element'),
fakedContent = js2xml({ [elementName]: schemaExample }, indentChar);
retVal = '\n' + indentContent(fakedContent, cIndent);
}
_.forOwn(schema.properties, (value, key) => {
propVal = convertSchemaToXML(key, value, _.get(value, 'xml.attribute'), indentChar, indent + 1);
if (_.get(value, 'xml.attribute')) {
attributes.push(`${key}="${propVal}"`);
else {
// go through all properties
var propVal, attributes = [], childNodes = '';
retVal = '\n' + cIndent + `<${tagPrefix}${name}`;
if (_.get(schema, 'xml.namespace')) {
let formattedTagPrefix = tagPrefix ?
`:${tagPrefix.slice(0,-1)}` :
'';
retVal += ` xmlns${formattedTagPrefix}="${schema.xml.namespace}"`
}
else {
childNodes += _.isString(propVal) ? propVal : '';
_.forOwn(schema.properties, (value, key) => {
propVal = convertSchemaToXML(key, value, _.get(value, 'xml.attribute'), indentChar, indent + 1, resolveTo);
if (_.get(value, 'xml.attribute')) {
attributes.push(`${key}="${propVal}"`);
}
else {
childNodes += _.isString(propVal) ? propVal : '';
}
});
if (attributes.length > 0) {
retVal += ' ' + attributes.join(' ');
}
});
if (attributes.length > 0) {
retVal += ' ' + attributes.join(' ');
retVal += '>';
retVal += childNodes;
retVal += `\n${cIndent}</${tagPrefix}${name}>`;
}
retVal += '>';
retVal += childNodes;
retVal += `\n${cIndent}</${tagPrefix}${name}>`;
}

@@ -70,3 +96,3 @@ else if (schema.type === 'array') {

extraIndent = isWrapped ? 1 : 0,
arrayElemName = _.get(schema, 'items.xml.name', name, 'arrayItem'),
arrayElemName = _.get(schema, 'items.xml.name', name || 'element'),
schemaItemsWithXmlProps = _.cloneDeep(schema.items),

@@ -76,4 +102,16 @@ contents;

schemaItemsWithXmlProps.xml = schema.xml;
contents = convertSchemaToXML(arrayElemName, schemaItemsWithXmlProps, false, indentChar, indent + extraIndent) +
convertSchemaToXML(arrayElemName, schemaItemsWithXmlProps, false, indentChar, indent + extraIndent);
if (resolveTo === 'example' && typeof schemaExample !== 'undefined') {
const fakedContent = js2xml({ [arrayElemName]: schemaExample }, indentChar);
contents = '\n' + indentContent(fakedContent, cIndent);
}
else {
let singleElementContent = convertSchemaToXML(arrayElemName, schemaItemsWithXmlProps, false, indentChar,
indent + extraIndent, resolveTo);
// Atleast 2 items per array will be added asame as JSON schema faker
contents = singleElementContent + singleElementContent;
}
if (isWrapped) {

@@ -89,5 +127,5 @@ return `\n${cIndent}<${tagPrefix}${name}>${contents}\n${cIndent}</${tagPrefix}${name}>`;

module.exports = function(name, schema, indentCharacter) {
module.exports = function(name, schema, indentCharacter, resolveTo) {
// substring(1) to trim the leading newline
return convertSchemaToXML(name, schema, false, indentCharacter, 0).substring(1);
return convertSchemaToXML(name, schema, false, indentCharacter, 0, resolveTo).substring(1);
};

@@ -94,0 +132,0 @@ /*

@@ -24,1 +24,2 @@ id|type|available options|default|description|usage|version

includeDeprecated|boolean|-|true|Select whether to include deprecated operations, parameters, and properties in generated collection or not|CONVERSION, VALIDATION|v2, v1
alwaysInheritAuthentication|boolean|-|false|Whether authentication details should be included on every request, or always inherited from the collection.|CONVERSION|v2, v1
{
"name": "openapi-to-postmanv2",
"version": "4.13.0",
"version": "4.14.0",
"description": "Convert a given OpenAPI specification to Postman Collection v2.0",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/postmanlabs/openapi-to-postman",

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