Skip to content

Commit 65b20d2

Browse files
author
Sophia Marie Terry
committed
Add ignore list and refactor logic into singularize method
1 parent 9bd6f97 commit 65b20d2

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { isPathParam, removePrefix, isSingleResourceIdentifier } from './resourc
44
const CAMEL_CASE = /[A-Z]?[a-z]+/g;
55
const CAMEL_CASE_WITH_ABBREVIATIONS = /[A-Z]+(?![a-z])|[A-Z]*[a-z]+/g;
66

7+
// List of capitalized nouns that should not be pluralized in any case.
8+
const IGNORE_LIST = ['Fts'];
9+
710
/**
811
* Returns IPA Compliant Operation ID.
912
*
@@ -40,7 +43,7 @@ export function generateOperationID(method, path) {
4043

4144
let opID = verb;
4245
for (let i = 0; i < nouns.length - 1; i++) {
43-
opID += inflection.singularize(nouns[i]);
46+
opID += singularize(nouns[i]);
4447
}
4548

4649
// singularize final noun, dependent on resource identifier - leave custom nouns alone
@@ -49,7 +52,7 @@ export function generateOperationID(method, path) {
4952
!camelCaseCustomMethod) ||
5053
verb === 'create'
5154
) {
52-
nouns[nouns.length - 1] = inflection.singularize(nouns[nouns.length - 1]);
55+
nouns[nouns.length - 1] = singularize(nouns[nouns.length - 1]);
5356
}
5457

5558
opID += nouns.pop();
@@ -92,3 +95,10 @@ function deriveActionVerb(method) {
9295
function capitalize(val) {
9396
return String(val).charAt(0).toUpperCase() + String(val).slice(1);
9497
}
98+
99+
function singularize(noun) {
100+
if (!IGNORE_LIST.includes(noun)) {
101+
return inflection.singularize(noun);
102+
}
103+
return noun;
104+
}

0 commit comments

Comments
 (0)