openapi-ts-request 0.13.3 → 0.13.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
<a href="https://github.com/openapi-ui/openapi-ts-request/blob/master/README-en_US.md">English</a> | 简体中文
|
|
6
6
|
|
|
7
|
-
根据 [Swagger2/OpenAPI3/Apifox](https://swagger.io/blog/news/whats-new-in-openapi-3-0/)
|
|
7
|
+
根据 [Swagger2/OpenAPI3/Apifox](https://swagger.io/blog/news/whats-new-in-openapi-3-0/) 文档生成:
|
|
8
|
+
|
|
9
|
+
- TS 类型
|
|
10
|
+
- 客户端请求函数
|
|
11
|
+
- 模拟请求响应服务
|
|
12
|
+
- 枚举和枚举翻译
|
|
13
|
+
- 类型字段翻译
|
|
14
|
+
- JSON Schemas
|
|
8
15
|
|
|
9
16
|
文档:[使用手册](https://github.com/openapi-ui/openapi-ts-request/issues/100)
|
|
10
17
|
|
|
@@ -38,6 +45,8 @@ pnpm i openapi-ts-request -D
|
|
|
38
45
|
import type { GenerateServiceProps } from 'openapi-ts-request';
|
|
39
46
|
|
|
40
47
|
export default {
|
|
48
|
+
// schemaPath: './openapi.json', // 本地openapi文件
|
|
49
|
+
// serversPath: './src/apis', // 接口存放路径
|
|
41
50
|
schemaPath: 'http://petstore.swagger.io/v2/swagger.json',
|
|
42
51
|
} as GenerateServiceProps;
|
|
43
52
|
```
|
|
@@ -61,12 +70,47 @@ export default [
|
|
|
61
70
|
|
|
62
71
|
在 `package.json` 的 `script` 中添加命令: `"openapi": "openapi-ts",`
|
|
63
72
|
|
|
64
|
-
|
|
73
|
+
运行:
|
|
65
74
|
|
|
66
75
|
```bash
|
|
67
76
|
npm run openapi
|
|
68
77
|
```
|
|
69
78
|
|
|
79
|
+
生成的接口:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
src/apis/index.ts #接口入口文件
|
|
83
|
+
src/apis/types.ts #类型定义文件
|
|
84
|
+
src/apis/pet.ts #接口文件
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
// src/apis/pet.ts
|
|
89
|
+
|
|
90
|
+
/* eslint-disable */
|
|
91
|
+
// @ts-ignore
|
|
92
|
+
import request from 'axios';
|
|
93
|
+
|
|
94
|
+
import * as API from './types';
|
|
95
|
+
|
|
96
|
+
/** Update an existing pet PUT /pet */
|
|
97
|
+
export async function updatePet(
|
|
98
|
+
body: API.Pet,
|
|
99
|
+
options?: { [key: string]: unknown }
|
|
100
|
+
) {
|
|
101
|
+
return request<unknown>(`/pet`, {
|
|
102
|
+
method: 'PUT',
|
|
103
|
+
headers: {
|
|
104
|
+
'Content-Type': 'application/json',
|
|
105
|
+
},
|
|
106
|
+
data: body,
|
|
107
|
+
...(options || {}),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ... 其他接口
|
|
112
|
+
```
|
|
113
|
+
|
|
70
114
|
### JS
|
|
71
115
|
|
|
72
116
|
任意目录 `xxx/xxx` 新建 `openapi-ts-request.config.js`
|
|
@@ -82,7 +126,7 @@ generateService({
|
|
|
82
126
|
|
|
83
127
|
在 `package.json` 的 `script` 中添加命令: `"openapi": "node xxx/xxx/openapi-ts-request.config.js"`
|
|
84
128
|
|
|
85
|
-
|
|
129
|
+
运行:
|
|
86
130
|
|
|
87
131
|
```bash
|
|
88
132
|
npm run openapi
|
|
@@ -103,7 +147,7 @@ generateService({
|
|
|
103
147
|
|
|
104
148
|
在 `package.json` 的 `script` 中添加命令: `"openapi": "ts-node xxx/xxx/openapi-ts-request.config.ts",`
|
|
105
149
|
|
|
106
|
-
|
|
150
|
+
运行:
|
|
107
151
|
|
|
108
152
|
```bash
|
|
109
153
|
npm run openapi
|
|
@@ -160,7 +204,7 @@ $ openapi --help
|
|
|
160
204
|
-h, --help display help for command
|
|
161
205
|
```
|
|
162
206
|
|
|
163
|
-
|
|
207
|
+
运行:
|
|
164
208
|
|
|
165
209
|
```bash
|
|
166
210
|
openapi --i ./spec.json --o ./apis
|
|
@@ -171,7 +215,7 @@ openapi --i ./spec.json --o ./apis
|
|
|
171
215
|
| 属性 | 必填 | 类型 | 默认值 | 说明 |
|
|
172
216
|
| --- | --- | --- | --- | --- |
|
|
173
217
|
| schemaPath | 是 | string | - | Swagger2/OpenAPI3 地址 |
|
|
174
|
-
| serversPath | 否 | string | './src/apis' |
|
|
218
|
+
| serversPath | 否 | string | './src/apis' | 运行结果文件夹路径 |
|
|
175
219
|
| requestLibPath | 否 | string | 'axios' | 自定义请求方法路径,例如:'@/request'、'node-fetch' |
|
|
176
220
|
| enableLogging | 否 | boolean | false | 是否开启日志 |
|
|
177
221
|
| priorityRule | 否 | string | 'include' | 模式规则,可选include/exclude/both |
|
package/package.json
CHANGED