Skip to content

Commit e68477c

Browse files
authored
Merge branch 'develop' into fix/issue#401
2 parents 3fd662a + 3245254 commit e68477c

16 files changed

+446
-65
lines changed

CHANGELOG.md

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

3+
#### v4.9.0 (February 06, 2023)
4+
* Fixed issue [#660](https://github.com/postmanlabs/openapi-to-postman/issues/660) where for certain XML request bodies, conversion was failing with TypeError.
5+
* Fixed issue where for some definitions having non-string URLs were failing conversion with TypeErrors.
6+
* Fixed issue where a test in-consistently kept failing due to uncertainity of jsf library.
7+
8+
#### v4.8.0 (January 24, 2023)
9+
* Added specifictionVersion field to validate result.
10+
311
#### v4.7.0 (January 16, 2023)
412
* Fixed an issue where same schema was being validated against examples multiple times during a conversion - using local cache here.
513
* Added a way to return analytics along with the result for better observability into the kind of schemas we get for conversion.

OPTIONS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
id|type|available options|default|description|usage
22
|---|---|---|---|---|---|
33
requestNameSource|enum|URL, Fallback|Fallback|Determines how the requests inside the generated collection will be named. If “Fallback” is selected, the request will be named after one of the following schema values: `summary`, `operationId`, `description`, `url`.|CONVERSION, VALIDATION
4-
indentCharacter|enum|Space, Tab|Space|Option for setting indentation character|CONVERSION
4+
indentCharacter|enum|Space, Tab|Space|Option for setting indentation character.|CONVERSION
55
collapseFolders|boolean|-|true|Importing will collapse all folders that have only one child element and lack persistent folder-level data.|CONVERSION
66
optimizeConversion|boolean|-|true|Optimizes conversion for large specification, disabling this option might affect the performance of conversion.|CONVERSION
77
requestParametersResolution|enum|Example, Schema|Schema|Select whether to generate the request 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
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
1111
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
12-
includeAuthInfoInExample|boolean|-|true|Select whether to include authentication parameters in the example request|CONVERSION
12+
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
1515
showMissingInSchemaErrors|boolean|-|false|MISSING_IN_SCHEMA indicates that an extra parameter was included in the request. For most use cases, this need not be considered an error.|VALIDATION
@@ -19,7 +19,7 @@ validateMetadata|boolean|-|false|Whether to show mismatches for incorrect name a
1919
ignoreUnresolvedVariables|boolean|-|false|Whether to ignore mismatches resulting from unresolved variables in the Postman request|VALIDATION
2020
strictRequestMatching|boolean|-|false|Whether requests should be strictly matched with schema operations. Setting to true will not include any matches where the URL path segments don't match exactly.|VALIDATION
2121
allowUrlPathVarMatching|boolean|-|false|Whether to allow matching path variables that are available as part of URL itself in the collection request|VALIDATION
22-
disableOptionalParameters|boolean|-|false|Whether to set optional parameters as disabled|CONVERSION
22+
enableOptionalParameters|boolean|-|true|Optional parameters aren't selected in the collection. Once enabled they will be selected in the collection and request as well.|CONVERSION
2323
keepImplicitHeaders|boolean|-|false|Whether to keep implicit headers from the OpenAPI specification, which are removed by default.|CONVERSION
2424
includeWebhooks|boolean|-|false|Select whether to include Webhooks in the generated collection|CONVERSION
2525
includeReferenceMap|boolean|-|false|Whether or not to include reference map or not as part of output|BUNDLE

lib/31XUtils/schemaUtils31X.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ module.exports = {
125125
schema.items = this.fixExamplesByVersion(schema.items);
126126
}
127127
else if (hasProperties) {
128-
const schemaProperties = Object.keys(schema.properties);
128+
const schemaProperties = _.keys(schema.properties);
129129
schemaProperties.forEach((property) => {
130130
schema.properties[property] = this.fixExamplesByVersion(schema.properties[property]);
131131
});
@@ -141,7 +141,7 @@ module.exports = {
141141
* @returns {boolean} Returns true if content is a binary type
142142
*/
143143
isBinaryContentType (bodyType, contentObj) {
144-
return Object.keys(contentObj[bodyType]).length === 0 && fileUploadTypes.includes(bodyType);
144+
return _.keys(contentObj[bodyType]).length === 0 && fileUploadTypes.includes(bodyType);
145145
},
146146

147147
getOuterPropsIfIsSupported(schema) {
@@ -152,7 +152,7 @@ module.exports = {
152152

153153
addOuterPropsToRefSchemaIfIsSupported(refSchema, outerProps) {
154154
const resolvedSchema = _.cloneDeep(refSchema),
155-
outerKeys = Object.keys(outerProps);
155+
outerKeys = _.keys(outerProps);
156156

157157
if (_.isObject(resolvedSchema) && _.isObject(outerProps)) {
158158
outerKeys.forEach((key) => {

lib/deref.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ module.exports = {
9191
/**
9292
* Creates a schema that's a union of all input schemas (only type: object is supported)
9393
*
94-
* @param {array} schemaArr REQUIRED - array of schemas, all of which must be valid in the returned object
94+
* @param {*} schema REQUIRED - OpenAPI defined schema object to be resolved
9595
* @param {string} parameterSourceOption REQUIRED tells that the schema object is of request or response
9696
* @param {*} components REQUIRED components in openapi spec.
9797
* @param {object} options - REQUIRED a list of options to indicate the type of resolution needed.
@@ -103,7 +103,7 @@ module.exports = {
103103
* @param {*} options.stackLimit Depth to which the schema should be resolved.
104104
* @returns {*} schema - schema that adheres to all individual schemas in schemaArr
105105
*/
106-
resolveAllOf: function (schemaArr, parameterSourceOption, components, {
106+
resolveAllOf: function (schema, parameterSourceOption, components, {
107107
resolveFor = RESOLVE_REF_DEFAULTS.resolveFor,
108108
resolveTo = RESOLVE_REF_DEFAULTS.resolveTo,
109109
stack = RESOLVE_REF_DEFAULTS.stack,
@@ -112,23 +112,25 @@ module.exports = {
112112
analytics = {}
113113
}) {
114114

115-
if (!(schemaArr instanceof Array)) {
115+
if (_.isEmpty(schema)) {
116116
return null;
117117
}
118118

119-
if (schemaArr.length === 1) {
120-
// for just one entry in allOf, don't need to enforce type: object restriction
121-
return this.resolveRefs(schemaArr[0], parameterSourceOption, components,
122-
{ stack, seenRef: _.cloneDeep(seenRef), resolveFor, resolveTo, stackLimit, analytics });
119+
let resolvedNonAllOfSchema = {};
120+
121+
// Resolve schema excluding allOf keyword which will be further used to resolve entire schema along with allOf
122+
if (_.keys(schema).length > 1) {
123+
resolvedNonAllOfSchema = this.resolveRefs(_.omit(schema, 'allOf'), parameterSourceOption, components,
124+
{ stack, seenRef: _.cloneDeep(seenRef), resolveFor, resolveTo, stackLimit, isAllOf: true, analytics });
123125
}
124126

125127
try {
126-
return mergeAllOf({
127-
allOf: schemaArr.map((schema) => {
128+
return mergeAllOf(_.assign(resolvedNonAllOfSchema, {
129+
allOf: _.map(schema.allOf, (schema) => {
128130
return this.resolveRefs(schema, parameterSourceOption, components,
129131
{ stack, seenRef: _.cloneDeep(seenRef), resolveFor, resolveTo, stackLimit, isAllOf: true, analytics });
130132
})
131-
}, {
133+
}), {
132134
resolvers: {
133135
// for keywords in OpenAPI schema that are not standard defined JSON schema keywords, use default resolver
134136
defaultResolver: (compacted) => { return compacted[0]; }
@@ -246,7 +248,7 @@ module.exports = {
246248
}) };
247249
}
248250
if (schema.allOf) {
249-
return this.resolveAllOf(schema.allOf, parameterSourceOption, components,
251+
return this.resolveAllOf(schema, parameterSourceOption, components,
250252
{
251253
resolveFor,
252254
resolveTo,
@@ -295,6 +297,9 @@ module.exports = {
295297
resolvedSchema = concreteUtils.addOuterPropsToRefSchemaIfIsSupported(resolvedSchema, outerProperties);
296298
}
297299
if (resolvedSchema) {
300+
if (schema.example) {
301+
resolvedSchema.example = schema.example;
302+
}
298303
let refResolvedSchema = this.resolveRefs(resolvedSchema, parameterSourceOption,
299304
components, {
300305
resolveFor,

lib/options.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ module.exports = {
7575
type: 'enum',
7676
default: 'Space',
7777
availableOptions: ['Space', 'Tab'],
78-
description: 'Option for setting indentation character',
78+
description: 'Option for setting indentation character.',
7979
external: true,
8080
usage: ['CONVERSION'],
8181
supportedIn: [VERSION20, VERSION30, VERSION31]
@@ -168,7 +168,7 @@ module.exports = {
168168
id: 'includeAuthInfoInExample',
169169
type: 'boolean',
170170
default: true,
171-
description: 'Select whether to include authentication parameters in the example request',
171+
description: 'Select whether to include authentication parameters in the example request.',
172172
external: true,
173173
usage: ['CONVERSION'],
174174
supportedIn: [VERSION20, VERSION30, VERSION31]
@@ -270,11 +270,12 @@ module.exports = {
270270
usage: ['VALIDATION']
271271
},
272272
{
273-
name: 'Disable optional parameters',
274-
id: 'disableOptionalParameters',
273+
name: 'Enable optional parameters',
274+
id: 'enableOptionalParameters',
275275
type: 'boolean',
276-
default: false,
277-
description: 'Whether to set optional parameters as disabled',
276+
default: true,
277+
description: 'Optional parameters aren\'t selected in the collection. ' +
278+
'Once enabled they will be selected in the collection and request as well.',
278279
external: true,
279280
usage: ['CONVERSION'],
280281
supportedIn: [VERSION20, VERSION30, VERSION31]

lib/schemaUtils.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ function safeSchemaFaker (oldSchema, resolveTo, resolveFor, parameterSourceOptio
196196
});
197197
}
198198

199+
if (schemaFormat === 'xml') {
200+
key += ' schemaFormatXML';
201+
}
202+
else {
203+
key += ' schemaFormatDEFAULT';
204+
}
205+
199206
key = hash(key);
200207
if (schemaFakerCache[key]) {
201208
return schemaFakerCache[key];
@@ -360,6 +367,11 @@ module.exports = {
360367
* @returns {string} string after replacing /{pet}/ with /:pet/
361368
*/
362369
fixPathVariablesInUrl: function (url) {
370+
// URL should always be string so update value if non-string value is found
371+
if (typeof url !== 'string') {
372+
return '';
373+
}
374+
363375
// All complicated logic removed
364376
// This simply replaces all instances of {text} with {{text}}
365377
// text cannot have any of these 3 chars: /{}
@@ -371,7 +383,7 @@ module.exports = {
371383
}
372384
return '{' + p1 + '}';
373385
};
374-
return url.replace(/(\{[^\/\{\}]+\})/g, replacer);
386+
return _.isString(url) ? url.replace(/(\{[^\/\{\}]+\})/g, replacer) : '';
375387
},
376388

377389
/**
@@ -1749,7 +1761,7 @@ module.exports = {
17491761
let { style, explode, startValue, propSeparator, keyValueSeparator, isExplodable } =
17501762
this.getParamSerialisationInfo(param, parameterSource, components);
17511763

1752-
if (options && options.disableOptionalParameters) {
1764+
if (options && !options.enableOptionalParameters) {
17531765
disabled = !param.required;
17541766
}
17551767

@@ -2797,7 +2809,7 @@ module.exports = {
27972809
// also, any endpoint-level params are merged into the returned pathItemObject
27982810
findMatchingRequestFromSchema: function (method, url, schema, options) {
27992811
// first step - get array of requests from schema
2800-
let parsedUrl = require('url').parse(url),
2812+
let parsedUrl = require('url').parse(_.isString(url) ? url : ''),
28012813
retVal = [],
28022814
pathToMatch,
28032815
matchedPath,

lib/schemapack.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ class SchemaPack {
142142
this.openapi = specParseResult.openapi;
143143
this.validated = true;
144144
this.validationResult = {
145-
result: true
145+
result: true,
146+
specificationVersion: concreteUtils.version
146147
};
147148
return this.validationResult;
148149
}

lib/xmlSchemaFaker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function convertSchemaToXML(name, schema, attribute, indentChar, indent) {
4747
attributes.push(`${key}="${propVal}"`);
4848
}
4949
else {
50-
childNodes += propVal;
50+
childNodes += _.isString(propVal) ? propVal : '';
5151
}
5252
});
5353
if (attributes.length > 0) {
@@ -66,7 +66,7 @@ function convertSchemaToXML(name, schema, attribute, indentChar, indent) {
6666
contents;
6767

6868
schemaItemsWithXmlProps.xml = schema.xml;
69-
contents = convertSchemaToXML(arrayElemName, schemaItemsWithXmlProps, false, indentChar, indent + extraIndent) +
69+
contents = convertSchemaToXML(arrayElemName, schemaItemsWithXmlProps, false, indentChar, indent + extraIndent) +
7070
convertSchemaToXML(arrayElemName, schemaItemsWithXmlProps, false, indentChar, indent + extraIndent);
7171
if (isWrapped) {
7272
return `\n${cIndent}<${tagPrefix}${name}>${contents}\n${cIndent}</${tagPrefix}${name}>`;

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.7.1",
3+
"version": "4.9.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)