Skip to content

Commit 37146f7

Browse files
CLOUDP-335986: Account for abbreviations in op ID names
1 parent 1ca1559 commit 37146f7

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ describe('tools/spectral/ipa/utils/operationIdGeneration.js', () => {
5858
expect(numberOfWords('createGroup')).toEqual(2);
5959
expect(numberOfWords('createGroupCluster')).toEqual(3);
6060
expect(numberOfWords('createGroupClusterIndex')).toEqual(4);
61+
expect(numberOfWords('getOpenAPIInfo')).toEqual(4);
62+
expect(numberOfWords('getCustomDNS')).toEqual(3);
6163
expect(numberOfWords('')).toEqual(0);
6264
});
6365
});
@@ -68,6 +70,8 @@ describe('tools/spectral/ipa/utils/operationIdGeneration.js', () => {
6870
'createAutoScalingConfiguration'
6971
);
7072
expect(shortenOperationId('getFederationSettingConnectedOrgConfigRoleMapping')).toEqual('getConfigRoleMapping');
73+
expect(shortenOperationId('getGroupAwsCustomDNS')).toEqual('getAwsCustomDNS');
74+
expect(shortenOperationId('getExampleOpenAPIInfo')).toEqual('getOpenAPIInfo');
7175
});
7276

7377
it('should make no change if the operation ID is <= 4 words long or undefined', () => {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const inflection = require('inflection');
22
import { isPathParam, removePrefix, isSingleResourceIdentifier } from './resourceEvaluation.js';
33

4-
const CAMEL_CASE = /[A-Z]?[a-z]+/g;
4+
const CAMEL_CASE = /[A-Z]*[a-z]+|[A-Z]+(?![a-z])/g;
5+
const CAMEL_CASE_WITH_ABBREVIATIONS = /[A-Z]+(?![a-z])|[A-Z]*[a-z]+/g;
56

67
/**
78
* Returns IPA Compliant Operation ID.
@@ -57,12 +58,12 @@ export function generateOperationID(method, path) {
5758
}
5859

5960
/**
60-
* Counts the number of words in a camelCase string.
61+
* Counts the number of words in a camelCase string. Allows for abbreviations (e.g. 'getOpenAPI').
6162
* @param operationId
6263
* @returns {number}
6364
*/
6465
export function numberOfWords(operationId) {
65-
return operationId.match(CAMEL_CASE)?.length || 0;
66+
return operationId.match(CAMEL_CASE_WITH_ABBREVIATIONS)?.length || 0;
6667
}
6768

6869
/**
@@ -71,7 +72,7 @@ export function numberOfWords(operationId) {
7172
* @returns {string}
7273
*/
7374
export function shortenOperationId(operationId) {
74-
const words = operationId.match(CAMEL_CASE);
75+
const words = operationId.match(CAMEL_CASE_WITH_ABBREVIATIONS);
7576
if (!words || words.length < 4) {
7677
return operationId; // Return as is if there are not enough words to shorten
7778
}

0 commit comments

Comments
 (0)