From b2cee1cc41dea03977a5d0947e06df059a2c5496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Neves?= Date: Tue, 15 Nov 2022 12:27:39 +0000 Subject: [PATCH 1/6] Honor allowOtherOptions of enums --- lib/options.js | 4 +++- lib/utils.js | 16 ++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/options.js b/lib/options.js index 0c55bdfd4..2fa6cf46c 100644 --- a/lib/options.js +++ b/lib/options.js @@ -34,9 +34,10 @@ module.exports = { /** * name - human-readable name for the option * id - key to pass the option with - * type - boolean or enum for now + * type - boolean, enum, array or integer for now * default - the value that's assumed if not specified * availableOptions - allowed values (only for type=enum) + * allowOtherOptions - allows user-defined values other than the ones specified in availableOptions (only for type=enum) * description - human-readable description of the item * external - whether the option is settable via the API * usage - array of supported types of usage (i.e. CONVERSION, VALIDATION) @@ -62,6 +63,7 @@ module.exports = { type: 'enum', default: 'Fallback', availableOptions: ['URL', 'Fallback'], + allowOtherOptions: true, description: '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: `description`, `operationid`, `url`.', diff --git a/lib/utils.js b/lib/utils.js index 1d1bcc90a..04ba6bb9e 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -31,19 +31,19 @@ module.exports = { } break; case 'enum': - // ignore case-sensitivity for string options - if ((defaultOptions[id].availableOptions.includes(userOptions[id])) || - (_.isString(userOptions[id]) && - _.map(defaultOptions[id].availableOptions, _.toLower).includes(_.toLower(userOptions[id])))) { + const { availableOptions, allowOtherOptions, defaultValue } = defaultOptions[id]; + if (_.isString(userOptions[id]) && + _.map(availableOptions, _.toLower).includes(_.toLower(userOptions[id]))) { + // ignore case-sensitivity for string options + retVal[id] = _.toLower(retVal[id]); + } + else if (allowOtherOptions || availableOptions.includes(userOptions[id])) { retVal[id] = userOptions[id]; } else { - retVal[id] = defaultOptions[id].default; + retVal[id] = _.isString(defaultValue) ? _.toLower(defaultValue) : defaultValue; } - // ignore case-sensitivity for string options - _.isString(retVal[id]) && (retVal[id] = _.toLower(retVal[id])); - break; case 'array': // user input needs to be parsed From 0453cf908c330915b1e7886945a07bcd41cb922f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Neves?= Date: Tue, 15 Nov 2022 12:46:44 +0000 Subject: [PATCH 2/6] Add OperationId value to requestNameSource --- OPTIONS.md | 2 +- lib/options.js | 4 +--- lib/schemaUtils.js | 17 +++++++++-------- lib/utils.js | 16 ++++++++-------- test/system/structure.test.js | 2 +- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/OPTIONS.md b/OPTIONS.md index c4a8a83df..45605ba03 100644 --- a/OPTIONS.md +++ b/OPTIONS.md @@ -1,6 +1,6 @@ id|type|available options|default|description|usage |---|---|---|---|---|---| -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: `description`, `operationid`, `url`.|CONVERSION, VALIDATION +requestNameSource|enum|URL, Fallback,OperationId|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: `description`, `operationid`, `url`.|CONVERSION, VALIDATION indentCharacter|enum|Space, Tab|Space|Option for setting indentation character|CONVERSION collapseFolders|boolean|-|true|Importing will collapse all folders that have only one child element and lack persistent folder-level data.|CONVERSION optimizeConversion|boolean|-|true|Optimizes conversion for large specification, disabling this option might affect the performance of conversion.|CONVERSION diff --git a/lib/options.js b/lib/options.js index 2fa6cf46c..f52ef70ea 100644 --- a/lib/options.js +++ b/lib/options.js @@ -37,7 +37,6 @@ module.exports = { * type - boolean, enum, array or integer for now * default - the value that's assumed if not specified * availableOptions - allowed values (only for type=enum) - * allowOtherOptions - allows user-defined values other than the ones specified in availableOptions (only for type=enum) * description - human-readable description of the item * external - whether the option is settable via the API * usage - array of supported types of usage (i.e. CONVERSION, VALIDATION) @@ -62,8 +61,7 @@ module.exports = { id: 'requestNameSource', type: 'enum', default: 'Fallback', - availableOptions: ['URL', 'Fallback'], - allowOtherOptions: true, + availableOptions: ['URL', 'Fallback', 'OperationId'], description: '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: `description`, `operationid`, `url`.', diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index c40ab673c..f77d2abf6 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -2466,8 +2466,8 @@ module.exports = { reqName = displayUrl || baseUrl; break; } - default : { - reqName = operation[options.requestNameSource]; + case 'operationid' : { + reqName = utils.insertSpacesInName(operation.operationId) || reqUrl; break; } } @@ -3643,6 +3643,13 @@ module.exports = { reqNameMismatch = (trimmedReqName !== expectedReqName); break; } + case 'operationid' : { + // operationId is usually camelcase or snake case + expectedReqName = utils.insertSpacesInName(schemaPath.operationId) || reqUrl; + expectedReqName = utils.trimRequestName(expectedReqName); + reqNameMismatch = (trimmedReqName !== expectedReqName); + break; + } case 'url' : { // actual value may differ in conversion as it uses local/global servers info to generate it // for now suggest actual path as request name @@ -3650,12 +3657,6 @@ module.exports = { reqNameMismatch = !_.endsWith(actualReqName, reqUrl); break; } - default : { - expectedReqName = schemaPath[options.requestNameSource]; - expectedReqName = utils.trimRequestName(expectedReqName); - reqNameMismatch = (trimmedReqName !== expectedReqName); - break; - } } if (reqNameMismatch) { diff --git a/lib/utils.js b/lib/utils.js index 04ba6bb9e..1d1bcc90a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -31,19 +31,19 @@ module.exports = { } break; case 'enum': - const { availableOptions, allowOtherOptions, defaultValue } = defaultOptions[id]; - if (_.isString(userOptions[id]) && - _.map(availableOptions, _.toLower).includes(_.toLower(userOptions[id]))) { - // ignore case-sensitivity for string options - retVal[id] = _.toLower(retVal[id]); - } - else if (allowOtherOptions || availableOptions.includes(userOptions[id])) { + // ignore case-sensitivity for string options + if ((defaultOptions[id].availableOptions.includes(userOptions[id])) || + (_.isString(userOptions[id]) && + _.map(defaultOptions[id].availableOptions, _.toLower).includes(_.toLower(userOptions[id])))) { retVal[id] = userOptions[id]; } else { - retVal[id] = _.isString(defaultValue) ? _.toLower(defaultValue) : defaultValue; + retVal[id] = defaultOptions[id].default; } + // ignore case-sensitivity for string options + _.isString(retVal[id]) && (retVal[id] = _.toLower(retVal[id])); + break; case 'array': // user input needs to be parsed diff --git a/test/system/structure.test.js b/test/system/structure.test.js index 7cf889cef..cf73264e2 100644 --- a/test/system/structure.test.js +++ b/test/system/structure.test.js @@ -82,7 +82,7 @@ const optionIds = [ name: 'Naming requests', type: 'enum', default: 'Fallback', - availableOptions: ['Url', 'Fallback'], + availableOptions: ['Url', 'Fallback', 'OperationId'], description: '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: `description`, `operationid`, `url`.' From 78fa47c90a381706d2b4fd2fe3b33f042db2332d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Neves?= Date: Tue, 15 Nov 2022 12:49:51 +0000 Subject: [PATCH 3/6] Dont add spaces --- lib/schemaUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index f77d2abf6..b7fc256ca 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -2467,7 +2467,7 @@ module.exports = { break; } case 'operationid' : { - reqName = utils.insertSpacesInName(operation.operationId) || reqUrl; + reqName = operation.operationId || reqUrl; break; } } From 1903a2d22ed98647c924c29c323598ee9aae8ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Neves?= Date: Tue, 15 Nov 2022 13:08:27 +0000 Subject: [PATCH 4/6] Add default case --- lib/schemaUtils.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index b7fc256ca..25209cb79 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -2470,6 +2470,8 @@ module.exports = { reqName = operation.operationId || reqUrl; break; } + default: + break; } if (!reqName) { throw new openApiErr(`requestNameSource (${options.requestNameSource})` + @@ -3657,6 +3659,8 @@ module.exports = { reqNameMismatch = !_.endsWith(actualReqName, reqUrl); break; } + default: + break; } if (reqNameMismatch) { From e86e44a31b3fa4f5e2e71437ca229b0956a23443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Neves?= Date: Tue, 15 Nov 2022 14:13:01 +0000 Subject: [PATCH 5/6] Fix trailing spaces --- lib/schemaUtils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index 25209cb79..9b294a58e 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -2470,7 +2470,7 @@ module.exports = { reqName = operation.operationId || reqUrl; break; } - default: + default: break; } if (!reqName) { @@ -3659,7 +3659,7 @@ module.exports = { reqNameMismatch = !_.endsWith(actualReqName, reqUrl); break; } - default: + default: break; } From a0de7ff5dc496db54fa490738f44553dfbf31805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Neves?= Date: Tue, 15 Nov 2022 16:37:10 +0000 Subject: [PATCH 6/6] Fix options.md --- OPTIONS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OPTIONS.md b/OPTIONS.md index 45605ba03..e93ecf56c 100644 --- a/OPTIONS.md +++ b/OPTIONS.md @@ -1,6 +1,6 @@ id|type|available options|default|description|usage |---|---|---|---|---|---| -requestNameSource|enum|URL, Fallback,OperationId|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: `description`, `operationid`, `url`.|CONVERSION, VALIDATION +requestNameSource|enum|URL, Fallback, OperationId|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: `description`, `operationid`, `url`.|CONVERSION, VALIDATION indentCharacter|enum|Space, Tab|Space|Option for setting indentation character|CONVERSION collapseFolders|boolean|-|true|Importing will collapse all folders that have only one child element and lack persistent folder-level data.|CONVERSION optimizeConversion|boolean|-|true|Optimizes conversion for large specification, disabling this option might affect the performance of conversion.|CONVERSION