Skip to content

Commit 69a1509

Browse files
authored
Merge pull request #799 from postmanlabs/release/v4.22.0
Release version v4.22.0
2 parents 42f45b9 + bbe6ad8 commit 69a1509

14 files changed

+555
-77
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## [Unreleased]
44

5+
## [v4.22.0] - 2024-07-10
6+
7+
### Chore
8+
9+
- Updated postman-collection to v4.4.0.
10+
511
## [v4.21.0] - 2024-05-17
612

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

621627
- Base release
622628

623-
[Unreleased]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.21.0...HEAD
629+
[Unreleased]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.22.0...HEAD
630+
631+
[v4.22.0]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.21.0...v4.22.0
624632

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

lib/common/versionUtils.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,10 @@ function getSpecVersion({ type, data, specificationVersion }) {
212212
const openapi30 = getVersionRegexp(VERSION_30),
213213
openapi31 = getVersionRegexp(VERSION_31),
214214
openapi20 = getVersionRegexp(VERSION_20),
215-
is30 = data.match(openapi30),
216-
is31 = data.match(openapi31),
217-
is20 = data.match(openapi20);
215+
is30 = typeof data === 'string' && data.match(openapi30),
216+
is31 = typeof data === 'string' && data.match(openapi31),
217+
is20 = typeof data === 'string' && data.match(openapi20);
218+
218219
let version = DEFAULT_SPEC_VERSION;
219220

220221
if (is30) {

lib/schemaUtils.js

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
* This file contains util functions that need OAS-awareness
33
* utils.js contains other util functions
44
*/
5-
6-
const { ParseError } = require('./common/ParseError.js');
7-
85
const { formatDataPath, checkIsCorrectType, isKnownType } = require('./common/schemaUtilsCommon.js'),
96
{ getConcreteSchemaUtils, isSwagger, validateSupportedVersion } = require('./common/versionUtils.js'),
107
async = require('async'),
11-
sdk = require('postman-collection'),
8+
{ Variable } = require('postman-collection/lib/collection/variable'),
9+
{ QueryParam } = require('postman-collection/lib/collection/query-param'),
10+
{ Header } = require('postman-collection/lib/collection/header'),
11+
{ ItemGroup } = require('postman-collection/lib/collection/item-group'),
12+
{ Item } = require('postman-collection/lib/collection/item'),
13+
{ FormParam } = require('postman-collection/lib/collection/form-param'),
14+
{ RequestAuth } = require('postman-collection/lib/collection/request-auth'),
15+
{ Response } = require('postman-collection/lib/collection/response'),
16+
{ RequestBody } = require('postman-collection/lib/collection/request-body'),
1217
schemaFaker = require('../assets/json-schema-faker.js'),
1318
deref = require('./deref.js'),
1419
_ = require('lodash'),
@@ -20,6 +25,7 @@ const { formatDataPath, checkIsCorrectType, isKnownType } = require('./common/sc
2025
{ validateSchema } = require('./ajValidation/ajvValidation'),
2126
inputValidation = require('./30XUtils/inputValidation'),
2227
traverseUtility = require('traverse'),
28+
{ ParseError } = require('./common/ParseError.js'),
2329
SCHEMA_FORMATS = {
2430
DEFAULT: 'default', // used for non-request-body data and json
2531
XML: 'xml' // used for request-body XMLs
@@ -511,15 +517,15 @@ module.exports = {
511517
if (serverVariables) {
512518
_.forOwn(serverVariables, (value, key) => {
513519
let description = this.getParameterDescription(value);
514-
variables.push(new sdk.Variable({
520+
variables.push(new Variable({
515521
key: key,
516522
value: value.default || '',
517523
description: description
518524
}));
519525
});
520526
}
521527
if (keyName) {
522-
variables.push(new sdk.Variable({
528+
variables.push(new Variable({
523529
key: keyName,
524530
value: serverUrl,
525531
type: 'string'
@@ -739,7 +745,7 @@ module.exports = {
739745
addCollectionItemsFromWebhooks: function(spec, generatedStore, components, options, schemaCache) {
740746
let webhooksObj = this.generateTrieFromPaths(spec, options, true),
741747
webhooksTree = webhooksObj.tree,
742-
webhooksFolder = new sdk.ItemGroup({ name: 'Webhooks' }),
748+
webhooksFolder = new ItemGroup({ name: 'Webhooks' }),
743749
variableStore = {},
744750
webhooksVariables = [];
745751

@@ -752,7 +758,7 @@ module.exports = {
752758
webhooksTree.root.children.hasOwnProperty(child) &&
753759
webhooksTree.root.children[child].requestCount > 0
754760
) {
755-
webhooksVariables.push(new sdk.Variable({
761+
webhooksVariables.push(new Variable({
756762
key: this.cleanWebhookName(child),
757763
value: '/',
758764
type: 'string'
@@ -838,7 +844,7 @@ module.exports = {
838844
// variableStore contains all the kinds of variable created.
839845
// Add only the variables with type 'collection' to generatedStore.collection.variables
840846
if (variableStore[key].type === 'collection') {
841-
const collectionVar = new sdk.Variable(variableStore[key]);
847+
const collectionVar = new Variable(variableStore[key]);
842848
generatedStore.collection.variables.add(collectionVar);
843849
}
844850
}
@@ -961,7 +967,7 @@ module.exports = {
961967
// Add all folders created from tags and corresponding operations
962968
// Iterate from bottom to top order to maintain tag order in spec
963969
_.forEachRight(tagFolders, (tagFolder, tagName) => {
964-
var itemGroup = new sdk.ItemGroup({
970+
var itemGroup = new ItemGroup({
965971
name: tagName,
966972
description: tagFolder.description
967973
});
@@ -981,7 +987,7 @@ module.exports = {
981987
// Add only the variables with type 'collection' to generatedStore.collection.variables
982988
_.forEach(variableStore, (variable) => {
983989
if (variable.type === 'collection') {
984-
const collectionVar = new sdk.Variable(variable);
990+
const collectionVar = new Variable(variable);
985991
generatedStore.collection.variables.add(collectionVar);
986992
}
987993
});
@@ -997,7 +1003,7 @@ module.exports = {
9971003
* resolve references while generating params.
9981004
* @param {object} options - a standard list of options that's globally passed around. Check options.js for more.
9991005
* @param {object} schemaCache - object storing schemaFaker and schmeResolution caches
1000-
* @returns {Array<object>} returns an array of sdk.Variable
1006+
* @returns {Array<object>} returns an array of Collection SDK Variable
10011007
*/
10021008
convertPathVariables: function(type, providedPathVars, commonPathVars, components, options, schemaCache) {
10031009
var variables = [];
@@ -1067,7 +1073,7 @@ module.exports = {
10671073
if (resource.requestCount > 1) {
10681074
// only return a Postman folder if this folder has>1 children in its subtree
10691075
// otherwise we can end up with 10 levels of folders with 1 request in the end
1070-
itemGroup = new sdk.ItemGroup({
1076+
itemGroup = new ItemGroup({
10711077
name: resource.name
10721078
// TODO: have to add auth here (but first, auth to be put into the openapi tree)
10731079
});
@@ -1308,9 +1314,9 @@ module.exports = {
13081314
*/
13091315
generateSdkParam: function (param, location) {
13101316
const sdkElementMap = {
1311-
'query': sdk.QueryParam,
1312-
'header': sdk.Header,
1313-
'path': sdk.Variable
1317+
'query': QueryParam,
1318+
'header': Header,
1319+
'path': Variable
13141320
};
13151321

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

1916-
reqHeader = new sdk.Header(convertedHeader);
1922+
reqHeader = new Header(convertedHeader);
19171923
reqHeader.description = this.getParameterDescription(header);
19181924

19191925
return reqHeader;
@@ -1936,7 +1942,7 @@ module.exports = {
19361942
originalParam,
19371943
paramArray = [],
19381944
updateOptions = {},
1939-
reqBody = new sdk.RequestBody(),
1945+
reqBody = new RequestBody(),
19401946
contentHeader,
19411947
contentTypes = {},
19421948
rDataMode,
@@ -2021,7 +2027,7 @@ module.exports = {
20212027
};
20222028

20232029
// add a content type header for each media type for the request body
2024-
contentHeader = new sdk.Header({
2030+
contentHeader = new Header({
20252031
key: 'Content-Type',
20262032
value: URLENCODED
20272033
});
@@ -2088,14 +2094,14 @@ module.exports = {
20882094
originalParam.type === 'string' &&
20892095
originalParam.format === 'binary'
20902096
) {
2091-
param = new sdk.FormParam({
2097+
param = new FormParam({
20922098
key: key,
20932099
value: '',
20942100
type: 'file'
20952101
});
20962102
}
20972103
else {
2098-
param = new sdk.FormParam({
2104+
param = new FormParam({
20992105
key: key,
21002106
value: value,
21012107
type: 'text'
@@ -2112,7 +2118,7 @@ module.exports = {
21122118
formdata: paramArray
21132119
};
21142120
// add a content type header for the pertaining media type
2115-
contentHeader = new sdk.Header({
2121+
contentHeader = new Header({
21162122
key: 'Content-Type',
21172123
value: FORM_DATA
21182124
});
@@ -2177,7 +2183,7 @@ module.exports = {
21772183
};
21782184
}
21792185

2180-
contentHeader = new sdk.Header({
2186+
contentHeader = new Header({
21812187
key: 'Content-Type',
21822188
value: bodyType
21832189
});
@@ -2246,7 +2252,7 @@ module.exports = {
22462252
responseMediaTypes = _.keys(response.content);
22472253

22482254
if (responseMediaTypes.length > 0) {
2249-
let acceptHeader = new sdk.Header({
2255+
let acceptHeader = new Header({
22502256
key: 'Accept',
22512257
value: responseMediaTypes[0]
22522258
});
@@ -2256,7 +2262,7 @@ module.exports = {
22562262
}
22572263
}
22582264

2259-
sdkResponse = new sdk.Response({
2265+
sdkResponse = new Response({
22602266
name: response.description,
22612267
code: code || 500,
22622268
header: responseHeaders,
@@ -2654,7 +2660,7 @@ module.exports = {
26542660
}
26552661

26562662
// creating the request object
2657-
item = new sdk.Item({
2663+
item = new Item({
26582664
name: reqName,
26592665
request: {
26602666
description: operation.description,
@@ -2672,7 +2678,7 @@ module.exports = {
26722678
};
26732679

26742680
thisAuthObject[authMap[authMeta.currentHelper]] = authMeta.helperAttributes;
2675-
item.request.auth = new sdk.RequestAuth(thisAuthObject);
2681+
item.request.auth = new RequestAuth(thisAuthObject);
26762682
}
26772683
else {
26782684
item.request.auth = authHelper;

lib/schemapack.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const { getConcreteSchemaUtils } = require('./common/versionUtils.js'),
66
Ajv = require('ajv'),
77
addFormats = require('ajv-formats'),
88
async = require('async'),
9-
sdk = require('postman-collection'),
9+
{ Collection } = require('postman-collection/lib/collection/collection'),
10+
{ Url } = require('postman-collection/lib/collection/url'),
1011
OasResolverOptions = {
1112
resolve: true, // Resolve external references
1213
jsonSchema: true // Treat $ref like JSON Schema and convert to OpenAPI Schema Objects
@@ -340,7 +341,7 @@ class SchemaPack {
340341

341342
// Creating a new instance of a Postman collection
342343
// All generated folders and requests will go inside this
343-
generatedStore.collection = new sdk.Collection({
344+
generatedStore.collection = new Collection({
344345
info: {
345346
name: utils.getCollectionName(_.get(openapi, 'info.title'))
346347
}
@@ -530,7 +531,7 @@ class SchemaPack {
530531
});
531532

532533
// SDK URL object. Get raw string representation.
533-
requestUrl = (new sdk.Url(requestUrl)).toString();
534+
requestUrl = (new Url(requestUrl)).toString();
534535
}
535536

536537
// 1. Look at transaction.request.URL + method, and find matching request from schema

libV2/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable one-var */
22
const _ = require('lodash'),
3-
sdk = require('postman-collection'),
3+
{ Collection } = require('postman-collection/lib/collection/collection'),
44
GraphLib = require('graphlib'),
55
generateSkeletonTreeFromOpenAPI = require('./helpers/collection/generateSkeletionTreeFromOpenAPI'),
66
generateCollectionFromOpenAPI = require('./helpers/collection/generateCollectionFromOpenAPI'),
@@ -45,7 +45,7 @@ module.exports = {
4545
case 'collection': {
4646
// dummy collection to be generated.
4747
const { data, variables } = generateCollectionFromOpenAPI(context, node);
48-
collection = new sdk.Collection(data);
48+
collection = new Collection(data);
4949

5050
collection = collection.toJSON();
5151

@@ -213,6 +213,11 @@ module.exports = {
213213
}
214214
});
215215

216+
// Remove duplicate variables as different requests could end up creating same variables
217+
if (!_.isEmpty(collection.variable)) {
218+
collection.variable = _.uniqBy(collection.variable, 'key');
219+
}
220+
216221
return cb(null, {
217222
result: true,
218223
output: [{

0 commit comments

Comments
 (0)