Skip to content

Commit 58c7213

Browse files
docs: add supportParseEnumDescByReg params
1 parent 43ed3d9 commit 58c7213

File tree

5 files changed

+14
-1
lines changed

5 files changed

+14
-1
lines changed

.changeset/eight-donuts-rush.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openapi-ts-request': minor
3+
---
4+
5+
feat: add supportParseEnumDescByReg func

README-en_US.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ $ openapi --help
210210
--isOnlyGenTypeScriptType <boolean> only generate typescript type (default: false)
211211
--isCamelCase <boolean> camelCase naming of controller files and request client (default: true)
212212
--isSupportParseEnumDesc <boolean> parse enum description to generate enum label (default: false)
213+
--supportParseEnumDescByReg <string> custom regex for parsing enum description
213214
-h, --help display help for command
214215
```
215216

@@ -251,6 +252,7 @@ openapi -i ./spec.json -o ./apis
251252
| isOnlyGenTypeScriptType | no | boolean | false | only generate typescript type |
252253
| isCamelCase | no | boolean | true | camelCase naming of controller files and request client |
253254
| isSupportParseEnumDesc | no | boolean | false | parse enum description to generate enum label, format example: `UserRole:User(Normal User)=0,Agent(Agent)=1,Admin(Administrator)=2` |
255+
| supportParseEnumDescByReg | no | string \| RegExp | - | custom regex for parsing enum descriptions. If set, replaces default parseDescriptionEnum method. Example: `/([^\s=<>/&;]+(?:\s+[^\s=<>/&;]+)*)\s*=\s*(\d+)/g` matches "Normal = 0" or "SampleMaker = 1" |
254256
| binaryMediaTypes | no | string[] | - | custom binary media types list, default includes: ['application/octet-stream', 'application/pdf', 'image/*', 'video/*', 'audio/*'] |
255257
| hook | no | [Custom Hook](#Custom-Hook) | - | custom hook |
256258

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ $ openapi --help
210210
--isOnlyGenTypeScriptType <boolean> only generate typescript type (default: false)
211211
--isCamelCase <boolean> camelCase naming of controller files and request client (default: true)
212212
--isSupportParseEnumDesc <boolean> parse enum description to generate enum label (default: false)
213+
--supportParseEnumDescByReg <string> custom regex for parsing enum description
213214
-h, --help display help for command
214215
```
215216

@@ -251,6 +252,7 @@ openapi --i ./spec.json --o ./apis
251252
| isOnlyGenTypeScriptType || boolean | false | 仅生成 typescript 类型 |
252253
| isCamelCase || boolean | true | 小驼峰命名文件和请求函数 |
253254
| isSupportParseEnumDesc || boolean | false | 解析枚举描述生成枚举标签,格式参考:`系统用户角色:User(普通用户)=0,Agent(经纪人)=1,Admin(管理员)=2` |
255+
| supportParseEnumDescByReg || string \| RegExp | - | 自定义正则表达式,用于解析 description 中的枚举定义。如果设置了此参数,将使用此正则表达式替代默认的 parseDescriptionEnum 方法。例如:`/([^\s=<>/&;]+(?:\s+[^\s=<>/&;]+)*)\s*=\s*(\d+)/g` 可以匹配 "普通 = 0" 或 "SampleMaker = 1" 这样的格式 |
254256
| binaryMediaTypes || string[] | - | 自定义二进制媒体类型列表,默认包含:['application/octet-stream', 'application/pdf', 'image/*', 'video/*', 'audio/*'] |
255257
| hook || [Custom Hook](#Custom-Hook) | - | 自定义 hook |
256258

agents.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ else if (isNodeProject) {
6969
| `isOnlyGenTypeScriptType` | boolean | `false` | Only types, no request functions | Type-only needs |
7070
| `isCamelCase` | boolean | `true` | Use camelCase naming | Consistent naming |
7171
| `isSupportParseEnumDesc` | boolean | `false` | Parse enum descriptions | Labeled enums |
72+
| `supportParseEnumDescByReg` | `string \| RegExp` | - | Custom regex for parsing enum descriptions. If set, replaces default parseDescriptionEnum method. Example: `/([^\s=<>/&;]+(?:\s+[^\s=<>/&;]+)*)\s*=\s*(\d+)/g` matches "普通 = 0" or "SampleMaker = 1" | Custom enum description formats |
7273

7374
#### Request Customization
7475

@@ -118,6 +119,7 @@ else if (isNodeProject) {
118119
| "支持文件上传" | Check OpenAPI for multipart | Auto-detects file uploads |
119120
| "翻译中文标签" | `isTranslateToEnglishTag: true` | Chinese to English tags |
120121
| "解析枚举描述" | `isSupportParseEnumDesc: true` | Enum with descriptions |
122+
| "自定义枚举解析正则" | `supportParseEnumDescByReg: /pattern/g` | Custom enum description parsing |
121123
| "生成JSON验证" | `isGenJsonSchemas: true` | Schema validation |
122124
| "前缀API路径" | `apiPrefix: "'api'"` | Add prefix to paths |
123125

@@ -205,6 +207,8 @@ else if (isNodeProject) {
205207
isTranslateToEnglishTag: true,
206208
isDisplayTypeLabel: true,
207209
isSupportParseEnumDesc: true,
210+
// Custom regex for parsing enum descriptions like "普通 = 0" or "SampleMaker = 1"
211+
supportParseEnumDescByReg: /([^\s=<>/&;]+(?:\s+[^\s=<>/&;]+)*)\s*=\s*(\d+)/g,
208212
isCamelCase: true,
209213
filterCaseInsensitive: true,
210214
}

src/bin/openapi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const params = program
9999
)
100100
.option(
101101
'--supportParseEnumDescByReg <string>',
102-
'custom regex for parsing enum description, e.g., "(\\S+)\\s*=\\s*(\\S+)"'
102+
'custom regex for parsing enum description'
103103
)
104104
.parse(process.argv)
105105
.opts();

0 commit comments

Comments
 (0)