Skip to content

Commit

Permalink
fix: support chinese for enum
Browse files Browse the repository at this point in the history
  • Loading branch information
wleven committed Nov 28, 2023
1 parent c67d332 commit e65de8b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/openApi/v2/parser/getEnum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const getEnum = (values?: (string | number)[]): Enum[] => {
}
return {
name: String(value)
.replace(/\W+/g, '_')
.replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]+/g, '_')
.replace(/^(\d+)/g, '_$1')
.replace(/([a-z])([A-Z]+)/g, '$1_$2')
.toUpperCase(),
Expand Down
2 changes: 1 addition & 1 deletion src/openApi/v3/parser/getEnum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const getEnum = (values?: (string | number)[]): Enum[] => {
}
return {
name: String(value)
.replace(/\W+/g, '_')
.replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]+/g, '_')
.replace(/^(\d+)/g, '_$1')
.replace(/([a-z])([A-Z]+)/g, '$1_$2')
.toUpperCase(),
Expand Down
3 changes: 2 additions & 1 deletion test/spec/v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,8 @@
"Warning",
"Error",
"'Single Quote'",
"\"Double Quotes\""
"\"Double Quotes\"",
"你好"
]
},
"EnumWithNumbers": {
Expand Down
4 changes: 3 additions & 1 deletion test/spec/v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -1561,9 +1561,11 @@
"Warning",
"Error",
"'Single Quote'",
"\"Double Quotes\""
"\"Double Quotes\"",
"你好"
]
},

"EnumWithNumbers": {
"description": "This is a simple enum with numbers",
"enum": [
Expand Down

0 comments on commit e65de8b

Please sign in to comment.