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 @@ -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);
});
});
Expand All @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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
}
Expand Down
Loading