Skip to content

Commit 896c435

Browse files
authored
Merge pull request #810 from postmanlabs/release/v4.23.0
Release version v4.23.0
2 parents 69a1509 + cde7edd commit 896c435

16 files changed

+420
-92
lines changed

CHANGELOG.md

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

33
## [Unreleased]
44

5+
## [v4.23.0] - 2024-07-22
6+
7+
### Added
8+
9+
- Conversion - Added option to set preferred request body content-type and use the first mentioned content-type as request body.
10+
11+
### Fixed
12+
13+
- Fixed issue with getOptions() API where default module version was still v1.
14+
- Fix to convert "format:binary" to "type:file" for requests with formdata body.
15+
16+
### Chore
17+
18+
- Replace traverse with neotraverse to reduce related dependencies.
19+
520
## [v4.22.0] - 2024-07-10
621

722
### Chore
@@ -626,7 +641,9 @@ Newer releases follow the [Keep a Changelog](https://keepachangelog.com/en/1.0.0
626641

627642
- Base release
628643

629-
[Unreleased]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.22.0...HEAD
644+
[Unreleased]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.23.0...HEAD
645+
646+
[v4.23.0]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.22.0...v4.23.0
630647

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

OPTIONS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ collapseFolders|boolean|-|true|Importing will collapse all folders that have onl
66
optimizeConversion|boolean|-|true|Optimizes conversion for large specification, disabling this option might affect the performance of conversion.|CONVERSION|v1
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|v1
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|v1
9+
disabledParametersValidation|boolean|-|true|Whether disabled parameters of collection should be validated|VALIDATION|v2, v1
910
parametersResolution|enum|Example, Schema|Schema|Select whether to generate the request and 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|v2, v1
1011
folderStrategy|enum|Paths, Tags|Paths|Select whether to create folders according to the spec’s paths or tags.|CONVERSION|v2, v1
12+
schemaFaker|boolean|-|true|Whether or not schemas should be faked.|CONVERSION|v2, v1
13+
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|v2, v1
1114
includeAuthInfoInExample|boolean|-|true|Select whether to include authentication parameters in the example request.|CONVERSION|v2, v1
1215
shortValidationErrors|boolean|-|false|Whether detailed error messages are required for request <> schema validation operations.|VALIDATION|v2, v1
1316
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|v2, v1
@@ -20,5 +23,8 @@ strictRequestMatching|boolean|-|false|Whether requests should be strictly matche
2023
allowUrlPathVarMatching|boolean|-|false|Whether to allow matching path variables that are available as part of URL itself in the collection request|VALIDATION|v2, v1
2124
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|v2, v1
2225
keepImplicitHeaders|boolean|-|false|Whether to keep implicit headers from the OpenAPI specification, which are removed by default.|CONVERSION|v2, v1
26+
includeWebhooks|boolean|-|false|Select whether to include Webhooks in the generated collection|CONVERSION|v2, v1
27+
includeReferenceMap|boolean|-|false|Whether or not to include reference map or not as part of output|BUNDLE|v2, v1
2328
includeDeprecated|boolean|-|true|Select whether to include deprecated operations, parameters, and properties in generated collection or not|CONVERSION, VALIDATION|v2, v1
2429
alwaysInheritAuthentication|boolean|-|false|Whether authentication details should be included on every request, or always inherited from the collection.|CONVERSION|v2, v1
30+
preferredRequestBodyType|enum|x-www-form-urlencoded, form-data, raw, first-listed|first-listed|When there are multiple content-types defined in the request body of OpenAPI, the conversion selects the preferred option content-type as request body.If "first-listed" is set, the first content-type defined in the OpenAPI spec will be selected.|CONVERSION|v2

lib/bundle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const _ = require('lodash'),
1414
jsonPointerDecodeAndReplace,
1515
generateObjectName
1616
} = require('./jsonPointer'),
17-
traverseUtility = require('traverse'),
17+
traverseUtility = require('neotraverse/legacy'),
1818
parse = require('./parse.js'),
1919
{ ParseError } = require('./common/ParseError'),
2020
Utils = require('./utils'),

lib/deref.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const _ = require('lodash'),
3535
isAllOf: false
3636
},
3737
DEFAULT_SCHEMA_UTILS = require('./30XUtils/schemaUtils30X'),
38-
traverseUtility = require('traverse'),
38+
traverseUtility = require('neotraverse/legacy'),
3939
PROPERTIES_TO_ASSIGN_ON_CASCADE = ['type', 'nullable'];
4040

4141
/**

lib/options.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ module.exports = {
4747
*
4848
* @param {string} [mode='document'] Describes use-case. 'document' will return an array
4949
* with all options being described. 'use' will return the default values of all options
50-
* @param {Object} criteria Decribes required criteria for options to be returned. can have properties
51-
* external: <boolean>
52-
* usage: <array> (Array of supported usage type - CONVERSION, VALIDATION)
53-
* version: <string> ('3.0' by default, supported values: '3.0', '3.1')
50+
* @param {Object} criteria Decribes required criteria for options to be returned.
51+
* @param {string} criteria.version The version of the OpenAPI spec to be converted
52+
* (can be one of '2.0', '3.0', '3.1')
53+
* @param {string} criteria.moduleVersion The version of the module (can be one of 'v1' or 'v2')
54+
* @param {Array<string>} criteria.usage The usage of the option (values can be one of 'CONVERSION', 'VALIDATION')
55+
* @param {boolean} criteria.external Whether the option is exposed to Postman App UI or not
5456
* @returns {mixed} An array or object (depending on mode) that describes available options
5557
*/
5658
getOptions: function(mode = 'document', criteria = {}) {
@@ -386,6 +388,20 @@ module.exports = {
386388
usage: ['CONVERSION'],
387389
supportedIn: [VERSION20, VERSION30, VERSION31],
388390
supportedModuleVersion: [MODULE_VERSION.V2, MODULE_VERSION.V1]
391+
},
392+
{
393+
name: 'Select request body type',
394+
id: 'preferredRequestBodyType',
395+
type: 'enum',
396+
default: 'first-listed',
397+
availableOptions: ['x-www-form-urlencoded', 'form-data', 'raw', 'first-listed'],
398+
description: 'When there are multiple content-types defined in the request body of OpenAPI, the conversion ' +
399+
'selects the preferred option content-type as request body.If "first-listed" is set, the first ' +
400+
'content-type defined in the OpenAPI spec will be selected.',
401+
external: false,
402+
usage: ['CONVERSION'],
403+
supportedIn: [VERSION20, VERSION30, VERSION31],
404+
supportedModuleVersion: [MODULE_VERSION.V2]
389405
}
390406
];
391407

@@ -408,7 +424,7 @@ module.exports = {
408424
}
409425

410426
// Setting default value
411-
criteria.moduleVersion = _.has(criteria, 'moduleVersion') ? criteria.moduleVersion : MODULE_VERSION.V1;
427+
criteria.moduleVersion = _.has(criteria, 'moduleVersion') ? criteria.moduleVersion : MODULE_VERSION.V2;
412428

413429
if (!_.includes(option.supportedModuleVersion, criteria.moduleVersion)) {
414430
return false;

lib/relatedFiles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const parse = require('./parse.js'),
2-
traverseUtility = require('traverse'),
2+
traverseUtility = require('neotraverse/legacy'),
33
BROWSER = 'browser',
44
{ DFS } = require('./dfs'),
55
{ isExtRef, removeLocalReferenceFromPath } = require('./jsonPointer');

lib/schemaUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const { formatDataPath, checkIsCorrectType, isKnownType } = require('./common/sc
2424
{ Node, Trie } = require('./trie.js'),
2525
{ validateSchema } = require('./ajValidation/ajvValidation'),
2626
inputValidation = require('./30XUtils/inputValidation'),
27-
traverseUtility = require('traverse'),
27+
traverseUtility = require('neotraverse/legacy'),
2828
{ ParseError } = require('./common/ParseError.js'),
2929
SCHEMA_FORMATS = {
3030
DEFAULT: 'default', // used for non-request-body data and json

libV2/schemaUtils.js

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const schemaFaker = require('../assets/json-schema-faker'),
4545
'ipv4', 'ipv6',
4646
'regex',
4747
'uuid',
48+
'binary',
4849
'json-pointer',
4950
'int64',
5051
'float',
@@ -479,11 +480,11 @@ let QUERYPARAM = 'query',
479480
* @param {Object} context - Global context
480481
* @param {Object} schema - Schema that is to be resolved
481482
* @param {Number} [stack] - Current recursion depth
482-
* @param {String} resolveFor - For which action this resoltion is to be done
483+
* @param {String} resolveFor - For which action this resolution is to be done
483484
* @param {Object} seenRef - Map of all the references that have been resolved
484485
* @todo: Explore using a directed graph/tree for maintaining seen ref
485486
*
486-
* @returns {Object} Returns the object that staisfies the schema
487+
* @returns {Object} Returns the object that satisfies the schema
487488
*/
488489
resolveSchema = (context, schema, stack = 0, resolveFor = CONVERSION, seenRef = {}) => {
489490
if (!schema) {
@@ -579,7 +580,6 @@ let QUERYPARAM = 'query',
579580
if (
580581
property.format === 'decimal' ||
581582
property.format === 'byte' ||
582-
property.format === 'binary' ||
583583
property.format === 'password' ||
584584
property.format === 'unix-time'
585585
) {
@@ -843,7 +843,6 @@ let QUERYPARAM = 'query',
843843
for (const prop in resolvedSchema.properties) {
844844
if (resolvedSchema.properties.hasOwnProperty(prop)) {
845845
if (
846-
resolvedSchema.properties[prop].format === 'binary' ||
847846
resolvedSchema.properties[prop].format === 'byte' ||
848847
resolvedSchema.properties[prop].format === 'decimal'
849848
) {
@@ -1358,7 +1357,6 @@ let QUERYPARAM = 'query',
13581357
}
13591358

13601359
if (
1361-
requestBodySchema.properties[prop].format === 'binary' ||
13621360
requestBodySchema.properties[prop].format === 'byte' ||
13631361
requestBodySchema.properties[prop].format === 'decimal'
13641362
) {
@@ -1518,7 +1516,7 @@ let QUERYPARAM = 'query',
15181516

15191517
// TODO: Add handling for headers from encoding
15201518

1521-
if (paramSchema && paramSchema.type === 'binary') {
1519+
if (paramSchema && paramSchema.type === 'string' && paramSchema.format === 'binary') {
15221520
param = {
15231521
key,
15241522
value: '',
@@ -1640,7 +1638,13 @@ let QUERYPARAM = 'query',
16401638

16411639
resolveRequestBodyForPostmanRequest = (context, operationItem) => {
16421640
let requestBody = operationItem.requestBody,
1643-
requestContent;
1641+
requestContent,
1642+
encodedRequestBody,
1643+
formDataRequestBody,
1644+
rawModeRequestBody;
1645+
1646+
const { preferredRequestBodyType: optionRequestBodyType } = context.computedOptions,
1647+
preferredRequestBodyType = optionRequestBodyType || 'first-listed';
16441648

16451649
if (!requestBody) {
16461650
return requestBody;
@@ -1659,15 +1663,38 @@ let QUERYPARAM = 'query',
16591663
};
16601664
}
16611665

1662-
if (requestContent[URLENCODED]) {
1663-
return resolveUrlEncodedRequestBodyForPostmanRequest(context, requestContent[URLENCODED]);
1666+
for (const contentType in requestContent) {
1667+
if (contentType === URLENCODED) {
1668+
encodedRequestBody = resolveUrlEncodedRequestBodyForPostmanRequest(context, requestContent[contentType]);
1669+
if (preferredRequestBodyType === 'first-listed') {
1670+
return encodedRequestBody;
1671+
}
1672+
}
1673+
else if (contentType === FORM_DATA) {
1674+
formDataRequestBody = resolveFormDataRequestBodyForPostmanRequest(context, requestContent[contentType]);
1675+
if (preferredRequestBodyType === 'first-listed') {
1676+
return formDataRequestBody;
1677+
}
1678+
}
1679+
else {
1680+
rawModeRequestBody = resolveRawModeRequestBodyForPostmanRequest(context, requestContent);
1681+
if (preferredRequestBodyType === 'first-listed') {
1682+
return rawModeRequestBody;
1683+
}
1684+
}
16641685
}
16651686

1666-
if (requestContent[FORM_DATA]) {
1667-
return resolveFormDataRequestBodyForPostmanRequest(context, requestContent[FORM_DATA]);
1687+
// Check if preferredRequestBodyType is provided and return the corresponding request body if available
1688+
if (preferredRequestBodyType) {
1689+
if (preferredRequestBodyType === 'x-www-form-urlencoded' && encodedRequestBody) {
1690+
return encodedRequestBody;
1691+
}
1692+
else if (preferredRequestBodyType === 'form-data' && formDataRequestBody) {
1693+
return formDataRequestBody;
1694+
}
16681695
}
16691696

1670-
return resolveRawModeRequestBodyForPostmanRequest(context, requestContent);
1697+
return rawModeRequestBody;
16711698
},
16721699

16731700
resolvePathItemParams = (context, operationParam, pathParam) => {
@@ -2236,6 +2263,7 @@ module.exports = {
22362263
},
22372264

22382265
resolveResponseForPostmanRequest,
2266+
resolveRequestBodyForPostmanRequest,
22392267
resolveRefFromSchema,
22402268
resolveSchema
22412269
};

libV2/validationUtils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ schemaFaker.option({
8585
maxItems: 20, // limit on maximum number of items faked for (type: array)
8686
useDefaultValue: true,
8787
ignoreMissingRefs: true,
88-
avoidExampleItemsLength: true // option to avoid validating type array schema example's minItems and maxItems props.
88+
avoidExampleItemsLength: true, // option to avoid validating type array schema example's minItems and maxItems props.
89+
failOnInvalidFormat: false
8990
});
9091

9192
/**

0 commit comments

Comments
 (0)