@fxri/swagger2api 1.0.14 → 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 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
  | 选项 | 类型 | 默认值 | 说明 |
@@ -60,32 +79,50 @@ npx swagger2api
60
79
 
61
80
  ```bash
62
81
  # 自定义配置文件
82
+
63
83
  npx swagger2api [--config,-c <path>]
84
+
85
+ npx @fxri/swagger2api [--config,-c <path>]
64
86
  ```
65
87
 
66
88
  ```bash
67
89
  # 快速模式,直接使用配置文件参数,若配置文件不存在或者参数不全,则不会进入该模式
90
+
68
91
  npx swagger2api [--quick,-q] [--quick,-q <boolean>]
92
+
93
+ npx @fxri/swagger2api [--quick,-q] [--quick,-q <boolean>]
69
94
  ```
70
95
 
71
96
  ```bash
72
97
  # 转换无{.+}get为query
98
+
73
99
  npx swagger2api [--convert-get,-cg] [--convert-get,-cg <boolean>]
100
+
101
+ npx @fxri/swagger2api [--convert-get,-cg] [--convert-get,-cg <boolean>]
74
102
  ```
75
103
 
76
104
  ```bash
77
105
  # 移除{.+}参数
106
+
78
107
  npx swagger2api [--remove-param,-rp] [--remove-param,-rp <boolean>]
108
+
109
+ npx @fxri/swagger2api [--remove-param,-rp] [--remove-param,-rp <boolean>]
79
110
  ```
80
111
 
81
112
  ```bash
82
113
  # 移除前缀索引
114
+
83
115
  npx swagger2api [--remove-prefix-index,-rpi <number>]
116
+
117
+ npx @fxri/swagger2api [--remove-prefix-index,-rpi <number>]
84
118
  ```
85
119
 
86
120
  ```bash
87
121
  # 移除使用--js参数时生成的d.ts文件
122
+
88
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>]
89
126
  ```
90
127
 
91
128
  ## 📝 PNPM 脚本
@@ -97,7 +134,13 @@ npx swagger2api [--remove-d.ts,-rd] [--remove-d.ts,-rd <boolean>]
97
134
  ```json
98
135
  {
99
136
  "scripts": {
100
- "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"
101
144
  }
102
145
  }
103
146
  ```
package/dist/api/api.js CHANGED
@@ -1,2 +1,3 @@
1
- import { Api } from "./index.js";
1
+ import { Api } from "./index";
2
2
  const api = new Api();
3
+ api.common.enumListGet({ param: { ids: "" } }).then((res) => console.log(res));