Skip to content

Commit 41d56b4

Browse files
author
Sophia Marie Terry
committed
CLOUDP-328283: Add new tests, debug for multiple word method names
1 parent 053d70f commit 41d56b4

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

tools/spectral/ipa/__tests__/utils/operationIdGeneration.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ describe('tools/spectral/ipa/utils/operationIdGeneration.js', () => {
2626

2727
it('should split camelCase method names', () => {
2828
expect(generateOperationID('addNode', '/groups/{groupId}/clusters/{clusterName}')).toEqual('addGroupClusterNode');
29+
expect(generateOperationID('get', '/api/atlas/v2/groups/byName/{groupName}')).toEqual('getGroupByName');
30+
expect(generateOperationID('', '/api/atlas/v2/groups/{groupId}/backup/exportBuckets/{exportBucketId}')).toEqual(
31+
'exportGroupBackupBuckets'
32+
);
2933
});
3034

31-
it('should accomodate legacy custom methods', () => {
35+
it('should accommodate legacy custom methods', () => {
3236
expect(generateOperationID('', '/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/restartPrimaries')).toEqual(
3337
'restartGroupClusterPrimaries'
3438
);

tools/spectral/ipa/rulesets/functions/utils/operationIdGeneration.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { singularize } from 'ember-inflector';
22
import { isPathParam, removePrefix, isSingleResourceIdentifier } from './resourceEvaluation.js';
3-
import { casing } from '@stoplight/spectral-functions';
43

5-
const CAMEL_CASE = /[A-Z]?[a-z]+/g
4+
const CAMEL_CASE = /[A-Z]?[a-z]+/g;
65

76
/**
87
* Returns IPA Compliant Operation ID.
@@ -12,17 +11,15 @@ const CAMEL_CASE = /[A-Z]?[a-z]+/g
1211
*/
1312
export function generateOperationID(method, path) {
1413
let resourceIdentifier = removePrefix(path);
15-
let nouns = resourceIdentifier
16-
.split('/')
17-
.filter((section) => section.length > 0 && !isPathParam(section))
18-
.map((noun) => capitalize(noun));
14+
let nouns = resourceIdentifier.split('/').filter((section) => section.length > 0 && !isPathParam(section));
1915

2016
// legacy custom method - use end of path as custom method name
2117
if (!method) {
22-
method = path.split('/').pop();
23-
nouns.pop();
18+
method = nouns.pop();
2419
}
2520

21+
nouns = nouns.map((noun) => capitalize(noun));
22+
2623
let verb = deriveActionVerb(method);
2724

2825
// if custom method name is multiple words, add trailing nouns to the operation ID

0 commit comments

Comments
 (0)