Skip to content

Commit 81e4e5f

Browse files
authored
CLOUDP-328313: Quickfix for legacy custom methods (#823)
1 parent a5f2763 commit 81e4e5f

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ describe('tools/spectral/ipa/utils/operationIdGeneration.js', () => {
2828
expect(generateOperationID('addNode', '/groups/{groupId}/clusters/{clusterName}')).toEqual('addGroupClusterNode');
2929
expect(generateOperationID('get', '/api/atlas/v2/groups/byName/{groupName}')).toEqual('getGroupByName');
3030
expect(generateOperationID('', '/api/atlas/v2/groups/{groupId}/backup/exportBuckets/{exportBucketId}')).toEqual(
31-
'exportGroupBackupBucket'
31+
'exportGroupBackupBuckets'
3232
);
3333
});
3434

3535
it('should accommodate legacy custom methods', () => {
3636
expect(generateOperationID('', '/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/restartPrimaries')).toEqual(
3737
'restartGroupClusterPrimaries'
3838
);
39+
expect(generateOperationID('', '/api/atlas/v2/groups/{groupId}/pipelines/{pipelineName}/pause')).toEqual(
40+
'pauseGroupPipeline'
41+
);
3942
});
4043
});

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ export function generateOperationID(method, path) {
2424
// legacy custom method - use end of path as custom method name
2525
if (!method) {
2626
method = nouns.pop();
27+
resourceIdentifier = resourceIdentifier.slice(0, resourceIdentifier.lastIndexOf('/'));
2728
}
2829

2930
nouns = nouns.map((noun) => capitalize(noun));
3031

3132
let verb = deriveActionVerb(method);
33+
const camelCaseCustomMethod = method.length > verb.length;
3234

3335
// if custom method name is multiple words, add trailing nouns to the operation ID
34-
if (method.length > verb.length) {
36+
if (camelCaseCustomMethod) {
3537
nouns.push(method.slice(verb.length));
3638
}
3739

@@ -40,10 +42,10 @@ export function generateOperationID(method, path) {
4042
opID += inflection.singularize(nouns[i]);
4143
}
4244

43-
// singularize final noun, dependent on resource identifier
45+
// singularize final noun, dependent on resource identifier - leave custom nouns alone
4446
if (
45-
isPathParam(resourceIdentifier.split('/').pop()) ||
46-
isSingleResourceIdentifier(resourceIdentifier) ||
47+
((isPathParam(resourceIdentifier.split('/').pop()) || isSingleResourceIdentifier(resourceIdentifier)) &&
48+
!camelCaseCustomMethod) ||
4749
verb === 'create'
4850
) {
4951
nouns[nouns.length - 1] = inflection.singularize(nouns[nouns.length - 1]);

0 commit comments

Comments
 (0)