Skip to content

Commit 99dfabe

Browse files
committed
Addressed comments
1 parent 804382e commit 99dfabe

File tree

4 files changed

+41
-29
lines changed

4 files changed

+41
-29
lines changed

lib/schemapack.js

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
'use strict';
22

3-
// This is the default collection name if one can't be inferred from the OpenAPI spec
4-
const COLLECTION_NAME = 'Imported from OpenAPI',
5-
{ getConcreteSchemaUtils } = require('./common/versionUtils.js'),
3+
const { getConcreteSchemaUtils } = require('./common/versionUtils.js'),
64
{ convertToOAS30IfSwagger } = require('./swaggerUtils/swaggerToOpenapi.js'),
75
BROWSER = 'browser',
86
Ajv = require('ajv'),
@@ -194,11 +192,7 @@ class SchemaPack {
194192
}
195193
// if the schema is validated, return the meta data as required.
196194
else if (this.validated) {
197-
let name = _.get(this.openapi, 'info.title');
198-
199-
if (_.isEmpty(name) || !_.isString(name)) {
200-
name = COLLECTION_NAME;
201-
}
195+
let name = utils.getCollectionName(_.get(this.openapi, 'info.title'));
202196

203197
return cb(null, {
204198
result: true,
@@ -219,11 +213,7 @@ class SchemaPack {
219213
return cb(null, validationResult);
220214
}
221215

222-
let name = _.get(this.openapi, 'info.title');
223-
224-
if (_.isEmpty(name) || !_.isString(name)) {
225-
name = COLLECTION_NAME;
226-
}
216+
let name = utils.getCollectionName(_.get(this.openapi, 'info.title'));
227217

228218
return cb(null, {
229219
result: true,
@@ -348,17 +338,11 @@ class SchemaPack {
348338
// Fix {scheme} and {path} vars in the URL to :scheme and :path
349339
openapi.baseUrl = schemaUtils.fixPathVariablesInUrl(openapi.baseUrl);
350340

351-
let name = _.get(this.openapi, 'info.title');
352-
353-
if (_.isEmpty(name) || !_.isString(name)) {
354-
name = COLLECTION_NAME;
355-
}
356-
357341
// Creating a new instance of a Postman collection
358342
// All generated folders and requests will go inside this
359343
generatedStore.collection = new sdk.Collection({
360344
info: {
361-
name: name
345+
name: utils.getCollectionName(_.get(openapi, 'info.title'))
362346
}
363347
});
364348

lib/utils.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
const _ = require('lodash');
1+
const _ = require('lodash'),
2+
3+
// This is the default collection name if one can't be inferred from the OpenAPI spec
4+
COLLECTION_NAME = 'Imported from OpenAPI';
25

36
// this will have non-OAS-related utils
47

@@ -142,5 +145,19 @@ module.exports = {
142145
res.push(segment);
143146
}
144147
return res.join('/');
148+
},
149+
150+
/**
151+
* Provides collection name to be used for generated collection
152+
*
153+
* @param {*} title - Definition title
154+
* @returns {String} - Collection name
155+
*/
156+
getCollectionName: function (title) {
157+
if (_.isEmpty(title) || !_.isString(title)) {
158+
return COLLECTION_NAME;
159+
}
160+
161+
return title;
145162
}
146163
};

libV2/helpers/collection/generateCollectionFromOpenAPI.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const _ = require('lodash'),
2+
utils = require('../../utils'),
23
generateAuthrForCollectionFromOpenAPI = require('./generateAuthForCollectionFromOpenAPI'),
3-
COLLECTION_NAME = 'Imported from OpenAPI',
44

55
/**
66
* Returns a description that's usable at the collection-level
@@ -93,16 +93,10 @@ module.exports = function ({ openapi }) {
9393

9494
const collectionVariables = resolveCollectionVariablesForBaseUrlFromServersObject(_.get(openapi, 'servers.0'));
9595

96-
let name = _.get(openapi, 'info.title');
97-
98-
if (_.isEmpty(name) || !_.isString(name)) {
99-
name = COLLECTION_NAME;
100-
}
101-
10296
return {
10397
data: {
10498
info: {
105-
name: name,
99+
name: utils.getCollectionName(_.get(openapi, 'info.title')),
106100
description: getCollectionDescription(openapi)
107101
},
108102
auth: generateAuthrForCollectionFromOpenAPI(openapi, openapi.security)

libV2/utils.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const sdk = require('postman-collection'),
22
_ = require('lodash'),
3+
4+
// This is the default collection name if one can't be inferred from the OpenAPI spec
5+
COLLECTION_NAME = 'Imported from OpenAPI',
36
generatePmResponseObject = (response) => {
47
const requestItem = generateRequestItemObject({ // eslint-disable-line no-use-before-define
58
request: response.originalRequest
@@ -182,6 +185,20 @@ module.exports = {
182185
return _.isString(url) ? url.replace(/(\{[^\/\{\}]+\})/g, replacer) : '';
183186
},
184187

188+
/**
189+
* Provides collection name to be used for generated collection
190+
*
191+
* @param {*} title - Definition title
192+
* @returns {String} - Collection name
193+
*/
194+
getCollectionName: function (title) {
195+
if (_.isEmpty(title) || !_.isString(title)) {
196+
return COLLECTION_NAME;
197+
}
198+
199+
return title;
200+
},
201+
185202
generatePmResponseObject,
186203
generateRequestItemObject
187204
};

0 commit comments

Comments
 (0)