Skip to content

Commit 54e56b1

Browse files
Merge pull request #243 from openapi-ui/main
feat: apifox support, incremental change support, cli concurrency and timeout support, uniquekey filpath support, openapi-ts merge to openapi
2 parents 8b6181e + e932466 commit 54e56b1

17 files changed

+1080
-249
lines changed

.changeset/happy-foxes-sip.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+
feat: cli concurrency and timeout support and uniquekey filpath support

.changeset/smooth-lights-greet.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: 新增增量修改,方法命名规范,合并openapi-ts和openapi命令

README-en_US.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ based on [Swagger2/OpenAPI3/Apifox](https://swagger.io/blog/news/whats-new-in-op
1313
- react-query/vue-query
1414
- type field label
1515
- JSON Schemas
16+
- Apifox Config
1617

1718
docs:[use docs](https://github.com/openapi-ui/openapi-ts-request/issues/100)
1819

@@ -25,6 +26,7 @@ docs:[use docs](https://github.com/openapi-ui/openapi-ts-request/issues/100)
2526
- support filter generate result by tags
2627
- support JSON/YAML specification
2728
- support translate chinese tag name to english tag name
29+
- support direct configuration of `apifox` `token` and `projectId` direct generation
2830

2931
## Usage
3032

@@ -181,9 +183,13 @@ $ openapi --help
181183
182184
Options:
183185
-V, --version output the version number
184-
-i, --input <string> OpenAPI specification, can be a path, url (required)
185-
-o, --output <string> output directory (required)
186+
-i, --input <string> OpenAPI specification, can be a path, url
187+
-o, --output <string> output directory
188+
-cfn, --configFileName <string> config file name
189+
-cfp, --configFilePath <string> config file path
190+
-u, --uniqueKey <string> unique key
186191
--requestLibPath <string> custom request lib path, for example: "@/request", "node-fetch" (default: "axios")
192+
-f, --full <boolean> full replacement (default: true)
187193
--enableLogging <boolean> open the log (default: false)
188194
--priorityRule <string> priority rule, include/exclude/both (default: "include")
189195
--includeTags <(string|RegExp)[]> generate code from include tags
@@ -221,6 +227,7 @@ openapi -i ./spec.json -o ./apis
221227
| schemaPath | yes | string | - | Swagger2/OpenAPI3 URL |
222228
| serversPath | no | string | './src/apis' | the folder path for the run results |
223229
| requestLibPath | no | string | 'axios' | custom request lib path, for example: '@/request', 'node-fetch' |
230+
| full | no | boolean | true | full replacement |
224231
| enableLogging | no | boolean | false | open the log |
225232
| priorityRule | no | string | 'include' | priority rule, include/exclude/both |
226233
| includeTags | no | (string\|RegExp)[] | - | generate code from include tags, priorityRule=include required |
@@ -237,6 +244,7 @@ openapi -i ./spec.json -o ./apis
237244
| isGenJsonSchemas | no | boolean | false | generate JSON Schemas |
238245
| mockFolder | no | string | - | mock file path, for example: './mocks' |
239246
| authorization | no | string | - | docs authorization |
247+
| apifoxConfig | no | [Apifox Config](#Apifox-Config) | - | apifox configs |
240248
| nullable | no | boolean | false | null instead of optional |
241249
| isTranslateToEnglishTag | no | boolean | false | translate chinese tag name to english tag name |
242250
| isOnlyGenTypeScriptType | no | boolean | false | only generate typescript type |
@@ -255,6 +263,17 @@ openapi -i ./spec.json -o ./apis
255263
| 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_ |
256264
| 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_ |
257265

266+
## Apifox-Config
267+
268+
| attribute | type | description | required |
269+
| --- | --- | --- | --- |
270+
| projectId | string | project id | true |
271+
| local | string | language(default:zh-CN) | false |
272+
| apifoxVersion | string | default: 2024-03-28, [current apifox version](https://api.apifox.com/v1/versions) | false |
273+
| includeTags | \* or string[] | default: \* | false |
274+
| excludeTags | string[] | default: [] | false |
275+
| apifoxToken | string | [get](https://docs.apifox.com/doc-5723694) | true |
276+
258277
## JSON Schemas
259278

260279
- default generate JSON Schemas based on [components.schemas](https://spec.openapis.org/oas/latest.html#components-object), JSON Schemas corresponding to [paths](https://spec.openapis.org/oas/latest.html#paths-object) currently need to be parsed by yourself
@@ -275,6 +294,33 @@ currently using [mockjs](http://mockjs.com) to generate mock data, the mocks fil
275294

276295
it is recommended to use a custom request function to adapt to uniapp. you can also use the `@uni-helper/axios-adapter` adapter. for details, see [【use docs 2.2】](https://github.com/openapi-ui/openapi-ts-request/issues/100)
277296

297+
## Notes on Upgrading Older Versions
298+
299+
- Current naming convention changes
300+
- Incremental changes have been made to the current version and will not affect previous versions.
301+
- The `openapi-ts` command can be deprecated to use `openapi`
302+
303+
### The configuration follows the naming convention of the old version as follows
304+
305+
```typescript
306+
import type { APIDataType } from 'openapi-ts-request/dist/generator/type';
307+
import {
308+
genDefaultFunctionName,
309+
resolveFunctionName,
310+
stripDot,
311+
} from 'openapi-ts-request/dist/generator/util';
312+
313+
export default {
314+
hook: {
315+
customFunctionName(data: APIDataType, prefix: string) {
316+
if (data.operationId)
317+
return resolveFunctionName(stripDot(data.operationId), data.method);
318+
return data.method + genDefaultFunctionName(data.path, prefix);
319+
},
320+
},
321+
};
322+
```
323+
278324
## Contribute
279325

280326
### Development Environment

README.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
<!-- TODO:需要修改文档, 添加参数, 添加apifox的配置支持 -->
2+
13
## 介绍
24

35
[![GitHub Repo stars](https://img.shields.io/github/stars/openapi-ui/openapi-ts-request?style=social)](https://github.com/openapi-ui/openapi-ts-request) [![npm (scoped)](https://img.shields.io/npm/v/openapi-ts-request)](https://www.npmjs.com/package/openapi-ts-request) ![GitHub tag](https://img.shields.io/github/v/tag/openapi-ui/openapi-ts-request?include_prereleases)
@@ -13,6 +15,7 @@
1315
- react-query/vue-query
1416
- 类型字段翻译
1517
- JSON Schemas
18+
- Apifox Config
1619

1720
文档:[使用手册](https://github.com/openapi-ui/openapi-ts-request/issues/100)
1821

@@ -25,6 +28,7 @@
2528
- 支持通过 tags 过滤生成结果
2629
- 支持 JSON/YAML 定义文件
2730
- 支持将中文 tag 名称翻译为英文 tag 名称
31+
- 支持直接配置`apifox``token``projectId`直接生成
2832

2933
## 使用
3034

@@ -181,9 +185,13 @@ $ openapi --help
181185
182186
Options:
183187
-V, --version output the version number
184-
-i, --input <string> OpenAPI specification, can be a path, url (required)
185-
-o, --output <string> output directory (required)
188+
-i, --input <string> OpenAPI specification, can be a path, url
189+
-o, --output <string> output directory
190+
-cfn, --configFileName <string> config file name
191+
-cfp, --configFilePath <string> config file path
192+
-u, --uniqueKey <string> unique key
186193
--requestLibPath <string> custom request lib path, for example: "@/request", "node-fetch" (default: "axios")
194+
-f, --full <boolean> full replacement (default: true)
187195
--enableLogging <boolean> open the log (default: false)
188196
--priorityRule <string> priority rule, include/exclude/both (default: "include")
189197
--includeTags <(string|RegExp)[]> generate code from include tags
@@ -221,6 +229,7 @@ openapi --i ./spec.json --o ./apis
221229
| schemaPath || string | - | Swagger2/OpenAPI3 地址 |
222230
| serversPath || string | './src/apis' | 运行结果文件夹路径 |
223231
| requestLibPath || string | 'axios' | 自定义请求方法路径,例如:'@/request'、'node-fetch' |
232+
| full || boolean | true | 是否全量替换 |
224233
| enableLogging || boolean | false | 是否开启日志 |
225234
| priorityRule || string | 'include' | 模式规则,可选include/exclude/both |
226235
| includeTags || (string\|RegExp)[] | - | 根据指定的 tags 生成代码, priorityRule=include则必填 |
@@ -237,6 +246,7 @@ openapi --i ./spec.json --o ./apis
237246
| isGenJsonSchemas || boolean | false | 是否生成 JSON Schemas |
238247
| mockFolder || string | - | mock文件路径,例如:'./mocks' |
239248
| authorization || string | - | 文档权限凭证 |
249+
| apifoxConfig || [Apifox Config](#Apifox-Config) | - | apifox 配置 |
240250
| nullable || boolean | false | 使用 null 代替可选 |
241251
| isTranslateToEnglishTag || boolean | false | 将中文 tag 名称翻译成英文 tag 名称 |
242252
| isOnlyGenTypeScriptType || boolean | false | 仅生成 typescript 类型 |
@@ -255,6 +265,17 @@ openapi --i ./spec.json --o ./apis
255265
| 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_ |
256266
| customFileNames | (<br>operationObject: OperationObject,<br>apiPath: string,<br>apiMethod: string,<br>) => string[] | 自定义生成的请求客户端文件名称,可以返回多个文件名称的数组(表示生成多个文件). <br> _返回为空,则使用默认的方法获取_ |
257267

268+
## Apifox-Config
269+
270+
| 属性 | 类型 | 说明 | 必填 |
271+
| --- | --- | --- | --- |
272+
| projectId | string | 项目id | true |
273+
| local | string | 语言(默认:zh-CN) | false |
274+
| apifoxVersion | string | 默认: 2024-03-28, [获取当前版本](https://api.apifox.com/v1/versions) | false |
275+
| includeTags | \* 或 string[] | 默认: \* | false |
276+
| excludeTags | string[] | 默认: [] | false |
277+
| apifoxToken | string | [获取](https://docs.apifox.com/doc-5723694) | true |
278+
258279
## JSON Schemas
259280

260281
- 默认生成 [components.schemas](https://spec.openapis.org/oas/latest.html#components-object) 下面的 JSON Schemas,[paths](https://spec.openapis.org/oas/latest.html#paths-object) 对应的 JSON Schemas 目前需自行解析
@@ -275,6 +296,33 @@ export declare function patchSchema<T extends object>(
275296

276297
适配 uniapp 推荐采用自定义 request 函数的方式,你也可以使用 `@uni-helper/axios-adapter` 适配器,详情见 [【使用手册 2.2】](https://github.com/openapi-ui/openapi-ts-request/issues/100)
277298

299+
## 旧版本升级注意事项
300+
301+
- 当前命名规范修改
302+
- 当前版本已完成增量修改, 不会影响以前
303+
- 可以弃用`openapi-ts`命令, 直接使用`openapi`
304+
305+
### 沿用旧版本命名规范配置如下
306+
307+
```typescript
308+
import type { APIDataType } from 'openapi-ts-request/dist/generator/type';
309+
import {
310+
genDefaultFunctionName,
311+
resolveFunctionName,
312+
stripDot,
313+
} from 'openapi-ts-request/dist/generator/util';
314+
315+
export default {
316+
hook: {
317+
customFunctionName(data: APIDataType, prefix: string) {
318+
if (data.operationId)
319+
return resolveFunctionName(stripDot(data.operationId), data.method);
320+
return data.method + genDefaultFunctionName(data.path, prefix);
321+
},
322+
},
323+
};
324+
```
325+
278326
## 贡献
279327

280328
### 环境要求

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"lint": "eslint ./src --report-unused-disable-directives --max-warnings=0",
3232
"lint:fix": "eslint ./src --report-unused-disable-directives --max-warnings=0 --fix",
3333
"test": "rm -rf ./test/apis/ ./test/mocks && npm run build && cd ./test && node ./test.js && cd ..",
34+
"test:new": "npm run build && cd ./test && node ./test.js && cd ..",
3435
"test:windows": "rimraf ./test/apis/ ./test/mocks && npm run build && cd ./test && node ./test.js && cd ..",
3536
"prepare": "husky",
3637
"openapi-ts-request": "openapi-ts"
@@ -56,6 +57,7 @@
5657
"rimraf": "^6.0.1",
5758
"swagger2openapi": "^7.0.8",
5859
"tiny-pinyin": "^1.3.2",
60+
"ts-morph": "^25.0.1",
5961
"tslib": "^2.6.3"
6062
},
6163
"devDependencies": {
@@ -80,7 +82,7 @@
8082
"lint-staged": "^15.3.0",
8183
"openapi-types": "^12.1.3",
8284
"ts-node": "^10.9.2",
83-
"typescript": "5.7.3"
85+
"typescript": "5.8.2"
8486
},
8587
"keywords": [
8688
"openapi",

0 commit comments

Comments
 (0)