diff --git a/tools/spectral/ipa/__tests__/utils/operationIdGeneration.test.js b/tools/spectral/ipa/__tests__/utils/operationIdGeneration.test.js index d297df8832..6fb11e856c 100644 --- a/tools/spectral/ipa/__tests__/utils/operationIdGeneration.test.js +++ b/tools/spectral/ipa/__tests__/utils/operationIdGeneration.test.js @@ -58,6 +58,8 @@ describe('tools/spectral/ipa/utils/operationIdGeneration.js', () => { expect(numberOfWords('createGroup')).toEqual(2); expect(numberOfWords('createGroupCluster')).toEqual(3); expect(numberOfWords('createGroupClusterIndex')).toEqual(4); + expect(numberOfWords('getOpenAPIInfo')).toEqual(4); + expect(numberOfWords('getCustomDNS')).toEqual(3); expect(numberOfWords('')).toEqual(0); }); }); @@ -68,6 +70,8 @@ describe('tools/spectral/ipa/utils/operationIdGeneration.js', () => { 'createAutoScalingConfiguration' ); expect(shortenOperationId('getFederationSettingConnectedOrgConfigRoleMapping')).toEqual('getConfigRoleMapping'); + expect(shortenOperationId('getGroupAwsCustomDNS')).toEqual('getAwsCustomDNS'); + expect(shortenOperationId('getExampleOpenAPIInfo')).toEqual('getOpenAPIInfo'); }); it('should make no change if the operation ID is <= 4 words long or undefined', () => { diff --git a/tools/spectral/ipa/rulesets/functions/utils/operationIdGeneration.js b/tools/spectral/ipa/rulesets/functions/utils/operationIdGeneration.js index 4299b760e0..f25ca29bb5 100644 --- a/tools/spectral/ipa/rulesets/functions/utils/operationIdGeneration.js +++ b/tools/spectral/ipa/rulesets/functions/utils/operationIdGeneration.js @@ -2,6 +2,7 @@ const inflection = require('inflection'); import { isPathParam, removePrefix, isSingleResourceIdentifier } from './resourceEvaluation.js'; const CAMEL_CASE = /[A-Z]?[a-z]+/g; +const CAMEL_CASE_WITH_ABBREVIATIONS = /[A-Z]+(?![a-z])|[A-Z]*[a-z]+/g; /** * Returns IPA Compliant Operation ID. @@ -57,12 +58,12 @@ export function generateOperationID(method, path) { } /** - * Counts the number of words in a camelCase string. + * Counts the number of words in a camelCase string. Allows for abbreviations (e.g. 'getOpenAPI'). * @param operationId * @returns {number} */ export function numberOfWords(operationId) { - return operationId.match(CAMEL_CASE)?.length || 0; + return operationId.match(CAMEL_CASE_WITH_ABBREVIATIONS)?.length || 0; } /** @@ -71,7 +72,7 @@ export function numberOfWords(operationId) { * @returns {string} */ export function shortenOperationId(operationId) { - const words = operationId.match(CAMEL_CASE); + const words = operationId.match(CAMEL_CASE_WITH_ABBREVIATIONS); if (!words || words.length < 4) { return operationId; // Return as is if there are not enough words to shorten }