Skip to content

Commit 7214f2b

Browse files
committed
fix(enum): substitution of disallowed characters in key string
fixes #74 Signed-off-by: Vojtech Mašek <[email protected]>
1 parent 8e02cc1 commit 7214f2b

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/parser.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,11 @@ function defineEnum(
199199
return {
200200
name: typeName(definitionKey),
201201
properties: enumSchema && enumSchema.map((val) => ({
202-
name: isNumeric
203-
? descKeys ? descKeys[val.toString()] : val.toString()
204-
: val.toString(),
202+
name: (
203+
isNumeric
204+
? descKeys ? descKeys[val.toString()] : val.toString()
205+
: val.toString()
206+
).replace(/[\W\s]+/, '_'),
205207
value: val.toString(),
206208
})),
207209
description: replaceNewLines(enumDesc, '$1 * '),

tests/custom/api/models/right.enum.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ export enum Right {
66
VIEW_ALL = "VIEW_ALL",
77
VIEW_MY = "VIEW_MY",
88
VIEW_EDIT = "VIEW_EDIT",
9+
READ_WRITE = "READ WRITE",
910
CONTROL = "CONTROL",
1011
}

tests/custom/swagger.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ definitions:
263263
- "VIEW_ALL"
264264
- "VIEW_MY"
265265
- "VIEW_EDIT"
266+
- "READ WRITE"
266267
- "CONTROL"
267268
possition:
268269
type: integer

0 commit comments

Comments
 (0)