Skip to content

Commit 433cbe0

Browse files
Merge pull request #225 from openapi-ui/main
feat: 解析枚举描述生成枚举
2 parents 6e92fd7 + 08ba109 commit 433cbe0

File tree

15 files changed

+684
-271
lines changed

15 files changed

+684
-271
lines changed

.changeset/tame-tips-press.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+
parse enum description to generate enum label

.changeset/tiny-flies-watch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openapi-ts-request': patch
3+
---
4+
5+
perf: perf display number enum label

.changeset/weak-monkeys-hear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openapi-ts-request': patch
3+
---
4+
5+
docs: fix customType hook api

README-en_US.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ src/apis/app #app interface
8787

8888
```typescript
8989
// src/apis/pet.ts
90-
9190
/* eslint-disable */
9291
// @ts-ignore
9392
import request from 'axios';
@@ -205,6 +204,7 @@ $ openapi --help
205204
--isTranslateToEnglishTag <boolean> translate chinese tag name to english tag name (default: false)
206205
--isOnlyGenTypeScriptType <boolean> only generate typescript type (default: false)
207206
--isCamelCase <boolean> camelCase naming of controller files and request client (default: true)
207+
--isSupportParseEnumDesc <boolean> parse enum description to generate enum label (default: false)
208208
-h, --help display help for command
209209
```
210210

@@ -241,6 +241,7 @@ openapi -i ./spec.json -o ./apis
241241
| isTranslateToEnglishTag | no | boolean | false | translate chinese tag name to english tag name |
242242
| isOnlyGenTypeScriptType | no | boolean | false | only generate typescript type |
243243
| isCamelCase | no | boolean | true | camelCase naming of controller files and request client |
244+
| isSupportParseEnumDesc | no | boolean | false | parse enum description to generate enum label, format example: `UserRole:User(Normal User)=0,Agent(Agent)=1,Admin(Administrator)=2` |
244245
| hook | no | [Custom Hook](#Custom-Hook) | - | custom hook |
245246

246247
## Custom Hook
@@ -251,7 +252,7 @@ openapi -i ./spec.json -o ./apis
251252
| customFunctionName | (data: APIDataType) => string | custom request client function name |
252253
| customTypeName | (data: APIDataType) => string | custom type name |
253254
| customClassName | (tagName: string) => string | custom tag name |
254-
| customType | (<br>schemaObject: SchemaObject \| ReferenceObject,<br>namespace: string,<br>originGetType:(schemaObject: SchemaObject \| ReferenceObject, namespace: string) => string,<br>) => string | custom type <br> _returning a non-string will use the default method to get the type_ |
255+
| customType | ({<br>schemaObject: SchemaObject \| ReferenceObject,<br>namespace: string,<br>originGetType:(schemaObject: SchemaObject \| ReferenceObject, namespace: string, schemas?: ComponentsObject['schemas']) => string,<br>schemas?: ComponentsObject['schemas'],<br>}) => string | custom type <br> _returning a non-string will use the default method to get the type_ |
255256
| customFileNames | (<br>operationObject: OperationObject,<br>apiPath: string,<br>apiMethod: string,<br>) => string[] | custom generate request client controller file name, can return multiple: generate multiple files. <br> _if the return value is empty, the default getFileNames is used_ |
256257

257258
## JSON Schemas

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ src/apis/pet.ts #接口文件
8787

8888
```typescript
8989
// src/apis/pet.ts
90-
9190
/* eslint-disable */
9291
// @ts-ignore
9392
import request from 'axios';
@@ -205,6 +204,7 @@ $ openapi --help
205204
--isTranslateToEnglishTag <boolean> translate chinese tag name to english tag name (default: false)
206205
--isOnlyGenTypeScriptType <boolean> only generate typescript type (default: false)
207206
--isCamelCase <boolean> camelCase naming of controller files and request client (default: true)
207+
--isSupportParseEnumDesc <boolean> parse enum description to generate enum label (default: false)
208208
-h, --help display help for command
209209
```
210210

@@ -241,6 +241,7 @@ openapi --i ./spec.json --o ./apis
241241
| isTranslateToEnglishTag || boolean | false | 将中文 tag 名称翻译成英文 tag 名称 |
242242
| isOnlyGenTypeScriptType || boolean | false | 仅生成 typescript 类型 |
243243
| isCamelCase || boolean | true | 小驼峰命名文件和请求函数 |
244+
| isSupportParseEnumDesc || boolean | false | 解析枚举描述生成枚举标签,格式参考:`系统用户角色:User(普通用户)=0,Agent(经纪人)=1,Admin(管理员)=2` |
244245
| hook || [Custom Hook](#Custom-Hook) | - | 自定义 hook |
245246

246247
## 自定义 Hook
@@ -251,7 +252,7 @@ openapi --i ./spec.json --o ./apis
251252
| customFunctionName | (data: APIDataType) => string | 自定义请求方法函数名称 |
252253
| customTypeName | (data: APIDataType) => string | 自定义类型名称 |
253254
| customClassName | (tagName: string) => string | 自定义标签名 |
254-
| customType | (<br>schemaObject: SchemaObject \| ReferenceObject,<br>namespace: string,<br>originGetType:(schemaObject: SchemaObject \| ReferenceObject, namespace: string) => string,<br>) => string | 自定义类型 <br> _返回非字符串将使用默认方法获取type_ |
255+
| customType | ({<br>schemaObject: SchemaObject \| ReferenceObject,<br>namespace: string,<br>originGetType:(schemaObject: SchemaObject \| ReferenceObject, namespace: string, schemas?: ComponentsObject['schemas']) => string,<br>schemas?: ComponentsObject['schemas'],<br>}) => string | 自定义类型 <br> _返回非字符串将使用默认方法获取type_ |
255256
| customFileNames | (<br>operationObject: OperationObject,<br>apiPath: string,<br>apiMethod: string,<br>) => string[] | 自定义生成的请求客户端文件名称,可以返回多个文件名称的数组(表示生成多个文件). <br> _返回为空,则使用默认的方法获取_ |
256257

257258
## JSON Schemas

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"lint-staged": "^15.3.0",
8181
"openapi-types": "^12.1.3",
8282
"ts-node": "^10.9.2",
83-
"typescript": "5.7.2"
83+
"typescript": "5.7.3"
8484
},
8585
"keywords": [
8686
"openapi",

0 commit comments

Comments
 (0)