Skip to content

Release version v4.22.0 #799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]

## [v4.22.0] - 2024-07-10

### Chore

- Updated postman-collection to v4.4.0.

## [v4.21.0] - 2024-05-17

### Added
Expand Down Expand Up @@ -620,7 +626,9 @@ Newer releases follow the [Keep a Changelog](https://keepachangelog.com/en/1.0.0

- Base release

[Unreleased]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.21.0...HEAD
[Unreleased]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.22.0...HEAD

[v4.22.0]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.21.0...v4.22.0

[v4.21.0]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.20.1...v4.21.0

Expand Down
7 changes: 4 additions & 3 deletions lib/common/versionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,10 @@ function getSpecVersion({ type, data, specificationVersion }) {
const openapi30 = getVersionRegexp(VERSION_30),
openapi31 = getVersionRegexp(VERSION_31),
openapi20 = getVersionRegexp(VERSION_20),
is30 = data.match(openapi30),
is31 = data.match(openapi31),
is20 = data.match(openapi20);
is30 = typeof data === 'string' && data.match(openapi30),
is31 = typeof data === 'string' && data.match(openapi31),
is20 = typeof data === 'string' && data.match(openapi20);

let version = DEFAULT_SPEC_VERSION;

if (is30) {
Expand Down
60 changes: 33 additions & 27 deletions lib/schemaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
* This file contains util functions that need OAS-awareness
* utils.js contains other util functions
*/

const { ParseError } = require('./common/ParseError.js');

const { formatDataPath, checkIsCorrectType, isKnownType } = require('./common/schemaUtilsCommon.js'),
{ getConcreteSchemaUtils, isSwagger, validateSupportedVersion } = require('./common/versionUtils.js'),
async = require('async'),
sdk = require('postman-collection'),
{ Variable } = require('postman-collection/lib/collection/variable'),
{ QueryParam } = require('postman-collection/lib/collection/query-param'),
{ Header } = require('postman-collection/lib/collection/header'),
{ ItemGroup } = require('postman-collection/lib/collection/item-group'),
{ Item } = require('postman-collection/lib/collection/item'),
{ FormParam } = require('postman-collection/lib/collection/form-param'),
{ RequestAuth } = require('postman-collection/lib/collection/request-auth'),
{ Response } = require('postman-collection/lib/collection/response'),
{ RequestBody } = require('postman-collection/lib/collection/request-body'),
schemaFaker = require('../assets/json-schema-faker.js'),
deref = require('./deref.js'),
_ = require('lodash'),
Expand All @@ -20,6 +25,7 @@ const { formatDataPath, checkIsCorrectType, isKnownType } = require('./common/sc
{ validateSchema } = require('./ajValidation/ajvValidation'),
inputValidation = require('./30XUtils/inputValidation'),
traverseUtility = require('traverse'),
{ ParseError } = require('./common/ParseError.js'),
SCHEMA_FORMATS = {
DEFAULT: 'default', // used for non-request-body data and json
XML: 'xml' // used for request-body XMLs
Expand Down Expand Up @@ -511,15 +517,15 @@ module.exports = {
if (serverVariables) {
_.forOwn(serverVariables, (value, key) => {
let description = this.getParameterDescription(value);
variables.push(new sdk.Variable({
variables.push(new Variable({
key: key,
value: value.default || '',
description: description
}));
});
}
if (keyName) {
variables.push(new sdk.Variable({
variables.push(new Variable({
key: keyName,
value: serverUrl,
type: 'string'
Expand Down Expand Up @@ -739,7 +745,7 @@ module.exports = {
addCollectionItemsFromWebhooks: function(spec, generatedStore, components, options, schemaCache) {
let webhooksObj = this.generateTrieFromPaths(spec, options, true),
webhooksTree = webhooksObj.tree,
webhooksFolder = new sdk.ItemGroup({ name: 'Webhooks' }),
webhooksFolder = new ItemGroup({ name: 'Webhooks' }),
variableStore = {},
webhooksVariables = [];

Expand All @@ -752,7 +758,7 @@ module.exports = {
webhooksTree.root.children.hasOwnProperty(child) &&
webhooksTree.root.children[child].requestCount > 0
) {
webhooksVariables.push(new sdk.Variable({
webhooksVariables.push(new Variable({
key: this.cleanWebhookName(child),
value: '/',
type: 'string'
Expand Down Expand Up @@ -838,7 +844,7 @@ module.exports = {
// variableStore contains all the kinds of variable created.
// Add only the variables with type 'collection' to generatedStore.collection.variables
if (variableStore[key].type === 'collection') {
const collectionVar = new sdk.Variable(variableStore[key]);
const collectionVar = new Variable(variableStore[key]);
generatedStore.collection.variables.add(collectionVar);
}
}
Expand Down Expand Up @@ -961,7 +967,7 @@ module.exports = {
// Add all folders created from tags and corresponding operations
// Iterate from bottom to top order to maintain tag order in spec
_.forEachRight(tagFolders, (tagFolder, tagName) => {
var itemGroup = new sdk.ItemGroup({
var itemGroup = new ItemGroup({
name: tagName,
description: tagFolder.description
});
Expand All @@ -981,7 +987,7 @@ module.exports = {
// Add only the variables with type 'collection' to generatedStore.collection.variables
_.forEach(variableStore, (variable) => {
if (variable.type === 'collection') {
const collectionVar = new sdk.Variable(variable);
const collectionVar = new Variable(variable);
generatedStore.collection.variables.add(collectionVar);
}
});
Expand All @@ -997,7 +1003,7 @@ module.exports = {
* resolve references while generating params.
* @param {object} options - a standard list of options that's globally passed around. Check options.js for more.
* @param {object} schemaCache - object storing schemaFaker and schmeResolution caches
* @returns {Array<object>} returns an array of sdk.Variable
* @returns {Array<object>} returns an array of Collection SDK Variable
*/
convertPathVariables: function(type, providedPathVars, commonPathVars, components, options, schemaCache) {
var variables = [];
Expand Down Expand Up @@ -1067,7 +1073,7 @@ module.exports = {
if (resource.requestCount > 1) {
// only return a Postman folder if this folder has>1 children in its subtree
// otherwise we can end up with 10 levels of folders with 1 request in the end
itemGroup = new sdk.ItemGroup({
itemGroup = new ItemGroup({
name: resource.name
// TODO: have to add auth here (but first, auth to be put into the openapi tree)
});
Expand Down Expand Up @@ -1308,9 +1314,9 @@ module.exports = {
*/
generateSdkParam: function (param, location) {
const sdkElementMap = {
'query': sdk.QueryParam,
'header': sdk.Header,
'path': sdk.Variable
'query': QueryParam,
'header': Header,
'path': Variable
};

let generatedParam = {
Expand Down Expand Up @@ -1913,7 +1919,7 @@ module.exports = {
convertedHeader = _.get(this.convertParamsWithStyle(header, fakeData, parameterSource,
components, schemaCache, options), '[0]');

reqHeader = new sdk.Header(convertedHeader);
reqHeader = new Header(convertedHeader);
reqHeader.description = this.getParameterDescription(header);

return reqHeader;
Expand All @@ -1936,7 +1942,7 @@ module.exports = {
originalParam,
paramArray = [],
updateOptions = {},
reqBody = new sdk.RequestBody(),
reqBody = new RequestBody(),
contentHeader,
contentTypes = {},
rDataMode,
Expand Down Expand Up @@ -2021,7 +2027,7 @@ module.exports = {
};

// add a content type header for each media type for the request body
contentHeader = new sdk.Header({
contentHeader = new Header({
key: 'Content-Type',
value: URLENCODED
});
Expand Down Expand Up @@ -2088,14 +2094,14 @@ module.exports = {
originalParam.type === 'string' &&
originalParam.format === 'binary'
) {
param = new sdk.FormParam({
param = new FormParam({
key: key,
value: '',
type: 'file'
});
}
else {
param = new sdk.FormParam({
param = new FormParam({
key: key,
value: value,
type: 'text'
Expand All @@ -2112,7 +2118,7 @@ module.exports = {
formdata: paramArray
};
// add a content type header for the pertaining media type
contentHeader = new sdk.Header({
contentHeader = new Header({
key: 'Content-Type',
value: FORM_DATA
});
Expand Down Expand Up @@ -2177,7 +2183,7 @@ module.exports = {
};
}

contentHeader = new sdk.Header({
contentHeader = new Header({
key: 'Content-Type',
value: bodyType
});
Expand Down Expand Up @@ -2246,7 +2252,7 @@ module.exports = {
responseMediaTypes = _.keys(response.content);

if (responseMediaTypes.length > 0) {
let acceptHeader = new sdk.Header({
let acceptHeader = new Header({
key: 'Accept',
value: responseMediaTypes[0]
});
Expand All @@ -2256,7 +2262,7 @@ module.exports = {
}
}

sdkResponse = new sdk.Response({
sdkResponse = new Response({
name: response.description,
code: code || 500,
header: responseHeaders,
Expand Down Expand Up @@ -2654,7 +2660,7 @@ module.exports = {
}

// creating the request object
item = new sdk.Item({
item = new Item({
name: reqName,
request: {
description: operation.description,
Expand All @@ -2672,7 +2678,7 @@ module.exports = {
};

thisAuthObject[authMap[authMeta.currentHelper]] = authMeta.helperAttributes;
item.request.auth = new sdk.RequestAuth(thisAuthObject);
item.request.auth = new RequestAuth(thisAuthObject);
}
else {
item.request.auth = authHelper;
Expand Down
7 changes: 4 additions & 3 deletions lib/schemapack.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const { getConcreteSchemaUtils } = require('./common/versionUtils.js'),
Ajv = require('ajv'),
addFormats = require('ajv-formats'),
async = require('async'),
sdk = require('postman-collection'),
{ Collection } = require('postman-collection/lib/collection/collection'),
{ Url } = require('postman-collection/lib/collection/url'),
OasResolverOptions = {
resolve: true, // Resolve external references
jsonSchema: true // Treat $ref like JSON Schema and convert to OpenAPI Schema Objects
Expand Down Expand Up @@ -340,7 +341,7 @@ class SchemaPack {

// Creating a new instance of a Postman collection
// All generated folders and requests will go inside this
generatedStore.collection = new sdk.Collection({
generatedStore.collection = new Collection({
info: {
name: utils.getCollectionName(_.get(openapi, 'info.title'))
}
Expand Down Expand Up @@ -530,7 +531,7 @@ class SchemaPack {
});

// SDK URL object. Get raw string representation.
requestUrl = (new sdk.Url(requestUrl)).toString();
requestUrl = (new Url(requestUrl)).toString();
}

// 1. Look at transaction.request.URL + method, and find matching request from schema
Expand Down
9 changes: 7 additions & 2 deletions libV2/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable one-var */
const _ = require('lodash'),
sdk = require('postman-collection'),
{ Collection } = require('postman-collection/lib/collection/collection'),
GraphLib = require('graphlib'),
generateSkeletonTreeFromOpenAPI = require('./helpers/collection/generateSkeletionTreeFromOpenAPI'),
generateCollectionFromOpenAPI = require('./helpers/collection/generateCollectionFromOpenAPI'),
Expand Down Expand Up @@ -45,7 +45,7 @@ module.exports = {
case 'collection': {
// dummy collection to be generated.
const { data, variables } = generateCollectionFromOpenAPI(context, node);
collection = new sdk.Collection(data);
collection = new Collection(data);

collection = collection.toJSON();

Expand Down Expand Up @@ -213,6 +213,11 @@ module.exports = {
}
});

// Remove duplicate variables as different requests could end up creating same variables
if (!_.isEmpty(collection.variable)) {
collection.variable = _.uniqBy(collection.variable, 'key');
}

return cb(null, {
result: true,
output: [{
Expand Down
Loading
Loading