Skip to content

Commit b6f6a63

Browse files
authored
Merge branch 'develop' into feature/readme-update
2 parents 6436c07 + 2fad4af commit b6f6a63

24 files changed

+1327
-79
lines changed

.github/workflows/integration.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
node-version: '14.x'
1414
- run: npm install
1515
- run: npm run test-lint
16+
- run: npm run test-system
1617
- run: npm run test-unit
1718

1819
Regression:

.travis.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# OpenAPI-Postman Changelog
22

3+
#### v4.4.0 (November 29, 2022)
4+
* Fixed issue where collection folder name for paths were having extra spaces.
5+
* Fixed issue where pipelines were failing for certain node version.
6+
7+
#### v4.3.0 (October 17, 2022)
8+
* Fixed issue with nullable keywords getting validated incorrectly.
9+
310
#### v4.2.0 (August 10, 2022)
411
* Improved the way to detect a circular reference by adding a new condition
512
* A schema that comes from an allOf parent then we now return the same schema instead of defaulting to a schema with type as object, and no other properties

OPTIONS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ requestParametersResolution|enum|Example, Schema|Schema|Select whether to genera
88
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
99
folderStrategy|enum|Paths, Tags|Paths|Select whether to create folders according to the spec’s paths or tags.|CONVERSION
1010
schemaFaker|boolean|-|true|Whether or not schemas should be faked.|CONVERSION
11-
stackLimit|integer|-|10|Number of nesting limit till which schema resolution will happen. Increasing this limit may result in more time to convert collection depending on complexity of specification. (To make sure this option works correctly "optimizeConversion" option needs to be disabled)|CONVERSION
11+
stackLimit|integer|-|8|Number of nesting limit till which schema resolution will happen. Increasing this limit may result in more time to convert collection depending on complexity of specification. (To make sure this option works correctly "optimizeConversion" option needs to be disabled)|CONVERSION
1212
includeAuthInfoInExample|boolean|-|true|Select whether to include authentication parameters in the example request|CONVERSION
1313
shortValidationErrors|boolean|-|false|Whether detailed error messages are required for request <> schema validation operations.|VALIDATION
1414
validationPropertiesToIgnore|array|-|[]|Specific properties (parts of a request/response pair) to ignore during validation. Must be sent as an array of strings. Valid inputs in the array: PATHVARIABLE, QUERYPARAM, HEADER, BODY, RESPONSE_HEADER, RESPONSE_BODY|VALIDATION

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11

2-
![postman icon](https://raw.githubusercontent.com/postmanlabs/postmanlabs.github.io/develop/global-artefacts/postman-logo%2Btext-320x132.png)
2+
<img src="https://voyager.postman.com/logo/postman-logo-orange.svg" width="320" alt="The Postman Logo">
33

4-
*Supercharge your API workflow.*
4+
*Supercharge your API workflow.*
55
*Modern software is built on APIs. Postman helps you develop APIs faster.*
66

77
# OpenAPI 3.0, 3.1 and Swagger 2.0 to Postman Collection
88

9-
[![Build Status](https://travis-ci.org/postmanlabs/openapi-to-postman.svg?branch=master)](https://travis-ci.org/postmanlabs/openapi-to-postman)
10-
<a href="https://www.npmjs.com/package/openapi-to-postmanv2" alt="Latest Stable Version">![npm](https://img.shields.io/npm/v/openapi-to-postmanv2.svg)</a>
9+
![Build Status](https://github.com/postmanlabs/openapi-to-postman/actions/workflows/integration.yml/badge.svg)
10+
11+
<a href="https://www.npmjs.com/package/openapi-to-postmanv2" alt="Latest Stable Version">![npm](https://img.shields.io/npm/v/openapi-to-postmanv2.svg)</a>
1112
<a href="https://www.npmjs.com/package/openapi-to-postmanv2" alt="Total Downloads">![npm](https://img.shields.io/npm/dw/openapi-to-postmanv2.svg)</a>
1213

13-
#### Contents
14+
#### Contents
1415

1516
1. [Getting Started](#getting-started)
1617
2. [Command Line Interface](#command-line-interface)

lib/deref.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ const _ = require('lodash'),
2828
'double'
2929
],
3030
DEFAULT_SCHEMA_UTILS = require('./30XUtils/schemaUtils30X'),
31-
traverseUtility = require('traverse');
31+
traverseUtility = require('traverse'),
32+
PROPERTIES_TO_ASSIGN_ON_CASCADE = ['type', 'nullable'];
3233

3334
/**
3435
* @param {*} currentNode - the object from which you're trying to find references
@@ -148,7 +149,7 @@ module.exports = {
148149
*/
149150

150151
resolveRefs: function (schema, parameterSourceOption, components, schemaResolutionCache,
151-
resolveFor = 'CONVERSION', resolveTo = 'schema', stack = 0, seenRef = {}, stackLimit = 10, isAllOf = false) {
152+
resolveFor = 'CONVERSION', resolveTo = 'schema', stack = 0, seenRef = {}, stackLimit = 8, isAllOf = false) {
152153
var resolvedSchema, prop, splitRef,
153154
ERR_TOO_MANY_LEVELS = '<Error: Too many levels of nesting to fake this schema>';
154155
let concreteUtils = components && components.hasOwnProperty('concreteUtils') ?
@@ -171,6 +172,11 @@ module.exports = {
171172
resolveTo, stack, _.cloneDeep(seenRef), stackLimit);
172173
}
173174
return { anyOf: _.map(schema.anyOf, (schemaElement) => {
175+
PROPERTIES_TO_ASSIGN_ON_CASCADE.forEach((prop) => {
176+
if (_.isNil(schemaElement[prop]) && !_.isNil(schema[prop])) {
177+
schemaElement[prop] = schema[prop];
178+
}
179+
});
174180
return this.resolveRefs(schemaElement, parameterSourceOption, components, schemaResolutionCache, resolveFor,
175181
resolveTo, stack, _.cloneDeep(seenRef), stackLimit);
176182
}) };
@@ -181,8 +187,14 @@ module.exports = {
181187
resolveTo, stack, _.cloneDeep(seenRef), stackLimit);
182188
}
183189
return { oneOf: _.map(schema.oneOf, (schemaElement) => {
184-
return this.resolveRefs(schemaElement, parameterSourceOption, components, schemaResolutionCache, resolveFor,
185-
resolveTo, stack, _.cloneDeep(seenRef), stackLimit);
190+
PROPERTIES_TO_ASSIGN_ON_CASCADE.forEach((prop) => {
191+
if (_.isNil(schemaElement[prop]) && !_.isNil(schema[prop])) {
192+
schemaElement[prop] = schema[prop];
193+
}
194+
});
195+
196+
return this.resolveRefs(schemaElement, parameterSourceOption, components, schemaResolutionCache,
197+
resolveFor, resolveTo, stack, _.cloneDeep(seenRef), stackLimit);
186198
}) };
187199
}
188200
if (schema.allOf) {

lib/options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ module.exports = {
155155
name: 'Schema resolution nesting limit',
156156
id: 'stackLimit',
157157
type: 'integer',
158-
default: 10,
158+
default: 8,
159159
description: 'Number of nesting limit till which schema resolution will happen. Increasing this limit may' +
160160
' result in more time to convert collection depending on complexity of specification. (To make sure this' +
161161
' option works correctly "optimizeConversion" option needs to be disabled)',

lib/schemaUtils.js

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ module.exports = {
273273

274274
var computedOptions = _.clone(options);
275275

276-
computedOptions.stackLimit = 10;
276+
computedOptions.stackLimit = 8;
277277
// This is the score that is given to each spec on the basis of the
278278
// number of references present in spec and the number of requests that will be generated.
279279
// This ranges from 0-10.
@@ -990,7 +990,7 @@ module.exports = {
990990
// only return a Postman folder if this folder has>1 children in its subtree
991991
// otherwise we can end up with 10 levels of folders with 1 request in the end
992992
itemGroup = new sdk.ItemGroup({
993-
name: utils.insertSpacesInName(resource.name)
993+
name: resource.name
994994
// TODO: have to add auth here (but first, auth to be put into the openapi tree)
995995
});
996996
// If a folder has only one child which is a folder then we collapsed the child folder
@@ -1082,33 +1082,33 @@ module.exports = {
10821082
helper = {
10831083
type: 'basic',
10841084
basic: [
1085-
{ key: 'username', value: '<Basic Auth Username>' },
1086-
{ key: 'password', value: '<Basic Auth Password>' }
1085+
{ key: 'username', value: '{{basicAuthUsername}}' },
1086+
{ key: 'password', value: '{{basicAuthPassword}}' }
10871087
]
10881088
};
10891089
}
10901090
else if (_.toLower(securityDef.scheme) === 'bearer') {
10911091
helper = {
10921092
type: 'bearer',
1093-
bearer: [{ key: 'token', value: '<Bearer Token>' }]
1093+
bearer: [{ key: 'token', value: '{{bearerToken}}' }]
10941094
};
10951095
}
10961096
else if (_.toLower(securityDef.scheme) === 'digest') {
10971097
helper = {
10981098
type: 'digest',
10991099
digest: [
1100-
{ key: 'username', value: '<Digest Auth Username>' },
1101-
{ key: 'password', value: '<Digest Auth Password>' },
1102-
{ key: 'realm', value: '<realm>' }
1100+
{ key: 'username', value: '{{digestAuthUsername}}' },
1101+
{ key: 'password', value: '{{digestAuthPassword}}' },
1102+
{ key: 'realm', value: '{{realm}}' }
11031103
]
11041104
};
11051105
}
11061106
else if (_.toLower(securityDef.scheme) === 'oauth' || _.toLower(securityDef.scheme) === 'oauth1') {
11071107
helper = {
11081108
type: 'oauth1',
11091109
oauth1: [
1110-
{ key: 'consumerSecret', value: '<OAuth 1.0 Consumer Key>' },
1111-
{ key: 'consumerKey', value: '<OAuth 1.0 Consumer Secret>' },
1110+
{ key: 'consumerSecret', value: '{{consumerSecret}}' },
1111+
{ key: 'consumerKey', value: '{{consumerKey}}' },
11121112
{ key: 'addParamsToHeader', value: true }
11131113
]
11141114
};
@@ -1161,7 +1161,7 @@ module.exports = {
11611161
if (!_.isEmpty(flowObj.refreshUrl)) {
11621162
helper.oauth2.push({
11631163
key: 'redirect_uri',
1164-
value: _.isString(flowObj.refreshUrl) ? flowObj.refreshUrl : '{{OAuth2_CallbackURL}}'
1164+
value: _.isString(flowObj.refreshUrl) ? flowObj.refreshUrl : '{{oAuth2CallbackURL}}'
11651165
});
11661166
}
11671167

@@ -1170,7 +1170,7 @@ module.exports = {
11701170
if (!_.isEmpty(flowObj.tokenUrl)) {
11711171
helper.oauth2.push({
11721172
key: 'accessTokenUrl',
1173-
value: _.isString(flowObj.tokenUrl) ? flowObj.tokenUrl : '{{OAuth2_AccessTokenURL}}'
1173+
value: _.isString(flowObj.tokenUrl) ? flowObj.tokenUrl : '{{oAuth2AccessTokenURL}}'
11741174
});
11751175
}
11761176
}
@@ -1180,7 +1180,7 @@ module.exports = {
11801180
if (!_.isEmpty(flowObj.authorizationUrl)) {
11811181
helper.oauth2.push({
11821182
key: 'authUrl',
1183-
value: _.isString(flowObj.authorizationUrl) ? flowObj.authorizationUrl : '{{OAuth2_AuthURL}}'
1183+
value: _.isString(flowObj.authorizationUrl) ? flowObj.authorizationUrl : '{{oAuth2AuthURL}}'
11841184
});
11851185
}
11861186
}
@@ -1197,9 +1197,9 @@ module.exports = {
11971197
apikey: [
11981198
{
11991199
key: 'key',
1200-
value: _.isString(securityDef.name) ? securityDef.name : '<API Key Name>'
1200+
value: _.isString(securityDef.name) ? securityDef.name : '{{apiKeyName}}'
12011201
},
1202-
{ key: 'value', value: '<API Key>' },
1202+
{ key: 'value', value: '{{apiKey}}' },
12031203
{
12041204
key: 'in',
12051205
value: _.includes(['query', 'header'], securityDef.in) ? securityDef.in : 'header'
@@ -2015,26 +2015,28 @@ module.exports = {
20152015
}
20162016
else {
20172017
let getXmlVersionContent = (bodyContent) => {
2018-
const regExp = new RegExp('([<\\?xml]+[\\s{1,}]+[version="\\d.\\d"]+[\\sencoding="]+.{1,15}"\\?>)');
2019-
let xmlBody = bodyContent;
2018+
const regExp = new RegExp('([<\\?xml]+[\\s{1,}]+[version="\\d.\\d"]+[\\sencoding="]+.{1,15}"\\?>)');
2019+
let xmlBody = bodyContent;
20202020

2021-
if (!bodyContent.match(regExp)) {
2022-
const versionContent = '<?xml version="1.0" encoding="UTF-8"?>\n';
2023-
xmlBody = versionContent + xmlBody;
2024-
}
2025-
return xmlBody;
2026-
};
2021+
if (!bodyContent.match(regExp)) {
2022+
const versionContent = '<?xml version="1.0" encoding="UTF-8"?>\n';
2023+
xmlBody = versionContent + xmlBody;
2024+
}
2025+
return xmlBody;
2026+
},
2027+
headerFamily;
20272028

20282029
bodyData = this.convertToPmBodyData(contentObj[bodyType], requestType, bodyType,
20292030
PARAMETER_SOURCE.REQUEST, options.indentCharacter, components, options, schemaCache);
20302031

2031-
bodyData = (bodyType === TEXT_XML || bodyType === APP_XML) ?
2032+
headerFamily = this.getHeaderFamily(bodyType);
2033+
bodyData = (bodyType === TEXT_XML || bodyType === APP_XML || headerFamily === HEADER_TYPE.XML) ?
20322034
getXmlVersionContent(bodyData) :
20332035
bodyData;
20342036

20352037
updateOptions = {
20362038
mode: rDataMode,
2037-
raw: bodyType !== APP_JSON ?
2039+
raw: !_.isObject(bodyData) && _.isFunction(_.get(bodyData, 'toString')) ?
20382040
bodyData.toString() :
20392041
JSON.stringify(bodyData, null, options.indentCharacter)
20402042
};

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openapi-to-postmanv2",
3-
"version": "4.2.0",
3+
"version": "4.4.0",
44
"description": "Convert a given OpenAPI specification to Postman Collection v2.0",
55
"homepage": "https://github.com/postmanlabs/openapi-to-postman",
66
"bugs": "https://github.com/postmanlabs/openapi-to-postman/issues",

0 commit comments

Comments
 (0)