Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ describe('tools/spectral/ipa/utils/operationIdGeneration.js', () => {
expect(generateOperationID('addNode', '/groups/{groupId}/clusters/{clusterName}')).toEqual('addGroupClusterNode');
expect(generateOperationID('get', '/api/atlas/v2/groups/byName/{groupName}')).toEqual('getGroupByName');
expect(generateOperationID('', '/api/atlas/v2/groups/{groupId}/backup/exportBuckets/{exportBucketId}')).toEqual(
'exportGroupBackupBucket'
'exportGroupBackupBuckets'
);
});

it('should accommodate legacy custom methods', () => {
expect(generateOperationID('', '/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/restartPrimaries')).toEqual(
'restartGroupClusterPrimaries'
);
expect(generateOperationID('', '/api/atlas/v2/groups/{groupId}/pipelines/{pipelineName}/pause')).toEqual(
'pauseGroupPipeline'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ export function generateOperationID(method, path) {
// legacy custom method - use end of path as custom method name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] can be separate method for handling legacy operations right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I could probably make a method that contains the extra logic and calls on this function. Will be something to consider when I'm implementing the verbosity override - might refactor for use in generating a shorter recommended opId

if (!method) {
method = nouns.pop();
resourceIdentifier = resourceIdentifier.slice(0, resourceIdentifier.lastIndexOf('/'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test case to cover this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, two fixes covered by the legacy custom method section of tests now

Copy link
Member

@wtrocki wtrocki Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Do we need test for empty operationIds/resourceIdentifier not in the shape we expected?

}

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

let verb = deriveActionVerb(method);
const camelCaseCustomMethod = method.length > verb.length;

// if custom method name is multiple words, add trailing nouns to the operation ID
if (method.length > verb.length) {
if (camelCaseCustomMethod) {
nouns.push(method.slice(verb.length));
}

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

// singularize final noun, dependent on resource identifier
// singularize final noun, dependent on resource identifier - leave custom nouns alone
if (
isPathParam(resourceIdentifier.split('/').pop()) ||
isSingleResourceIdentifier(resourceIdentifier) ||
((isPathParam(resourceIdentifier.split('/').pop()) || isSingleResourceIdentifier(resourceIdentifier)) &&
!camelCaseCustomMethod) ||
verb === 'create'
) {
nouns[nouns.length - 1] = inflection.singularize(nouns[nouns.length - 1]);
Expand Down
Loading