@fxri/swagger2api 1.0.13 → 1.0.15
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 +46 -1
- package/dist/api/api.js +2 -1
- package/dist/api/index.d.ts +1300 -22863
- package/dist/api/index.js +388 -15393
- package/dist/api/kjt.d.ts +215 -118
- package/dist/api/kjt.js +83 -82
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,10 +24,16 @@ pnpm install @fxri/swagger2api
|
|
|
24
24
|
|
|
25
25
|
### 1. 生成接口代码
|
|
26
26
|
|
|
27
|
+
如果没装过其他名字叫 swagger2api 的工具,那么在 shell 中直接使用就行,如果装过同名工具,则需要带上 @fxri 作用域
|
|
28
|
+
|
|
27
29
|
```bash
|
|
28
30
|
npx swagger2api
|
|
29
31
|
```
|
|
30
32
|
|
|
33
|
+
```bash
|
|
34
|
+
npx @fxri/swagger2api
|
|
35
|
+
```
|
|
36
|
+
|
|
31
37
|
### 2. 配置文件说明
|
|
32
38
|
|
|
33
39
|
工具在脚本执行目录生成配置文件,作为生成接口时的默认参数,生成代码结束后,如果参数有改动,则会更新配置文件:
|
|
@@ -40,6 +46,19 @@ npx swagger2api
|
|
|
40
46
|
}
|
|
41
47
|
```
|
|
42
48
|
|
|
49
|
+
### 3. 调用接口
|
|
50
|
+
|
|
51
|
+
直接调用生成的API类方法:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { Api } from "./index"
|
|
55
|
+
|
|
56
|
+
const api = new Api()
|
|
57
|
+
api.getUsers().then((res) => console.log(res))
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
每个方法会返回 Promise,可通过 async/await 或 .then() 处理响应
|
|
61
|
+
|
|
43
62
|
## ⚙️ 配置选项
|
|
44
63
|
|
|
45
64
|
| 选项 | 类型 | 默认值 | 说明 |
|
|
@@ -54,36 +73,56 @@ npx swagger2api
|
|
|
54
73
|
| `--remove-prefix-index,-rpi` | number | `-1` | 移除前缀索引 |
|
|
55
74
|
| `--remove-d.ts,-rd` | boolean | `false` | 移除使用--js参数时生成的d.ts文件 |
|
|
56
75
|
|
|
76
|
+
扩展:[更多 swagger-typescript-api 配置选项](https://fig.io/manual/swagger-typescript-api)
|
|
77
|
+
|
|
57
78
|
## 🔧 CLI 命令
|
|
58
79
|
|
|
59
80
|
```bash
|
|
60
81
|
# 自定义配置文件
|
|
82
|
+
|
|
61
83
|
npx swagger2api [--config,-c <path>]
|
|
84
|
+
|
|
85
|
+
npx @fxri/swagger2api [--config,-c <path>]
|
|
62
86
|
```
|
|
63
87
|
|
|
64
88
|
```bash
|
|
65
89
|
# 快速模式,直接使用配置文件参数,若配置文件不存在或者参数不全,则不会进入该模式
|
|
90
|
+
|
|
66
91
|
npx swagger2api [--quick,-q] [--quick,-q <boolean>]
|
|
92
|
+
|
|
93
|
+
npx @fxri/swagger2api [--quick,-q] [--quick,-q <boolean>]
|
|
67
94
|
```
|
|
68
95
|
|
|
69
96
|
```bash
|
|
70
97
|
# 转换无{.+}get为query
|
|
98
|
+
|
|
71
99
|
npx swagger2api [--convert-get,-cg] [--convert-get,-cg <boolean>]
|
|
100
|
+
|
|
101
|
+
npx @fxri/swagger2api [--convert-get,-cg] [--convert-get,-cg <boolean>]
|
|
72
102
|
```
|
|
73
103
|
|
|
74
104
|
```bash
|
|
75
105
|
# 移除{.+}参数
|
|
106
|
+
|
|
76
107
|
npx swagger2api [--remove-param,-rp] [--remove-param,-rp <boolean>]
|
|
108
|
+
|
|
109
|
+
npx @fxri/swagger2api [--remove-param,-rp] [--remove-param,-rp <boolean>]
|
|
77
110
|
```
|
|
78
111
|
|
|
79
112
|
```bash
|
|
80
113
|
# 移除前缀索引
|
|
114
|
+
|
|
81
115
|
npx swagger2api [--remove-prefix-index,-rpi <number>]
|
|
116
|
+
|
|
117
|
+
npx @fxri/swagger2api [--remove-prefix-index,-rpi <number>]
|
|
82
118
|
```
|
|
83
119
|
|
|
84
120
|
```bash
|
|
85
121
|
# 移除使用--js参数时生成的d.ts文件
|
|
122
|
+
|
|
86
123
|
npx swagger2api [--remove-d.ts,-rd] [--remove-d.ts,-rd <boolean>]
|
|
124
|
+
|
|
125
|
+
npx @fxri/swagger2api [--remove-d.ts,-rd] [--remove-d.ts,-rd <boolean>]
|
|
87
126
|
```
|
|
88
127
|
|
|
89
128
|
## 📝 PNPM 脚本
|
|
@@ -95,7 +134,13 @@ npx swagger2api [--remove-d.ts,-rd] [--remove-d.ts,-rd <boolean>]
|
|
|
95
134
|
```json
|
|
96
135
|
{
|
|
97
136
|
"scripts": {
|
|
98
|
-
"api": "swagger2api --axios --responses --remove-prefix-index 0 --quick"
|
|
137
|
+
"api": "swagger2api --axios --responses --remove-prefix-index 0 --quick"
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
{
|
|
142
|
+
"scripts": {
|
|
143
|
+
"api": "npx @fxri/swagger2api --axios --responses --remove-prefix-index 0 --quick"
|
|
99
144
|
}
|
|
100
145
|
}
|
|
101
146
|
```
|
package/dist/api/api.js
CHANGED