Skip to content

Add OperationId as a possible value of requestNameSource #642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion OPTIONS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`.',
Expand Down
19 changes: 12 additions & 7 deletions lib/schemaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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})` +
Expand Down Expand Up @@ -3643,19 +3645,22 @@ 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
expectedReqName = reqUrl;
reqNameMismatch = !_.endsWith(actualReqName, reqUrl);
break;
}
default : {
expectedReqName = schemaPath[options.requestNameSource];
expectedReqName = utils.trimRequestName(expectedReqName);
reqNameMismatch = (trimmedReqName !== expectedReqName);
default:
break;
}
}

if (reqNameMismatch) {
Expand Down
2 changes: 1 addition & 1 deletion test/system/structure.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`.'
Expand Down