Skip to content

Commit ac69ede

Browse files
author
Allart Kooiman
committed
Pluralize array names
1 parent fb0e0a5 commit ac69ede

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

package-lock.json

Lines changed: 30 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
"commander": "^9.3.0",
6464
"fs-extra": "^10.1.0",
6565
"handlebars": "^4.7.7",
66-
"json-schema-ref-parser": "^9.0.9"
66+
"json-schema-ref-parser": "^9.0.9",
67+
"pluralize": "^8.0.0"
6768
},
6869
"devDependencies": {
6970
"@angular-devkit/build-angular": "13.3.7",
@@ -91,6 +92,7 @@
9192
"@types/jest": "27.5.1",
9293
"@types/node": "17.0.38",
9394
"@types/node-fetch": "2.6.1",
95+
"@types/pluralize": "^0.0.29",
9496
"@types/qs": "6.9.7",
9597
"@typescript-eslint/eslint-plugin": "5.27.0",
9698
"@typescript-eslint/parser": "5.27.0",

src/openApi/v3/parser/getOperationParameterName.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import camelCase from 'camelcase';
2+
import pluralize from 'pluralize';
23

34
const reservedWords =
45
/^(arguments|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|eval|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|static|super|switch|this|throw|true|try|typeof|var|void|while|with|yield)$/g;
@@ -10,7 +11,7 @@ const reservedWords =
1011
export const getOperationParameterName = (value: string): string => {
1112
const clean = value
1213
.replace(/^[^a-zA-Z]+/g, '')
13-
.replace(/[^s]\[\]$/, 's')
14+
.replace(/^(.*)\[\]$/, (match, p1) => pluralize(p1))
1415
.replace(/[^\w\-]+/g, '-')
1516
.trim();
1617
return camelCase(clean).replace(reservedWords, '_$1');

0 commit comments

Comments
 (0)