diff --git a/OPTIONS.md b/OPTIONS.md index c4a8a83df..e93ecf56c 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 0c55bdfd4..f52ef70ea 100644 --- a/lib/options.js +++ b/lib/options.js @@ -34,7 +34,7 @@ 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) * description - human-readable description of the item @@ -61,7 +61,7 @@ module.exports = { id: 'requestNameSource', 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`.', diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index c40ab673c..9b294a58e 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -2466,10 +2466,12 @@ module.exports = { reqName = displayUrl || baseUrl; break; } - default : { - reqName = operation[options.requestNameSource]; + case 'operationid' : { + reqName = operation.operationId || reqUrl; break; } + default: + break; } if (!reqName) { throw new openApiErr(`requestNameSource (${options.requestNameSource})` + @@ -3643,6 +3645,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 +3659,8 @@ module.exports = { reqNameMismatch = !_.endsWith(actualReqName, reqUrl); break; } - default : { - expectedReqName = schemaPath[options.requestNameSource]; - expectedReqName = utils.trimRequestName(expectedReqName); - reqNameMismatch = (trimmedReqName !== expectedReqName); + default: break; - } } if (reqNameMismatch) { 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`.'