@gopowerteam/request-generate 0.1.11 → 0.1.13
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/dist/{chunk-7BMEVKSG.mjs → chunk-LBEPSBX6.mjs} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +52 -0
- package/dist/index.mjs +53 -1
- package/dist/templates/partials/export-service-class.hbs +28 -0
- package/dist/templates/partials/export-service-import.hbs +1 -1
- package/dist/templates/partials/export-service-operation.hbs +41 -28
- package/dist/vite-plugin/index.d.ts +1 -1
- package/dist/vite-plugin/index.mjs +1 -1
- package/package.json +14 -14
|
@@ -5,7 +5,7 @@ var __publicField = (obj, key, value) => {
|
|
|
5
5
|
return value;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
// ../../node_modules/.pnpm/tsup@6.
|
|
8
|
+
// ../../node_modules/.pnpm/tsup@6.6.3_6qtx7vkbdhwvdm4crzlegk4mvi/node_modules/tsup/assets/esm_shims.js
|
|
9
9
|
import { fileURLToPath } from "url";
|
|
10
10
|
import path from "path";
|
|
11
11
|
var getFilename = () => fileURLToPath(import.meta.url);
|
package/dist/index.d.ts
CHANGED
|
@@ -113,7 +113,7 @@ type GenerateClient = {
|
|
|
113
113
|
services: Service[]
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
type UnkownVersionDocument = OpenAPIV3.Document & OpenAPIV2.Document;
|
|
117
117
|
declare class Generate {
|
|
118
118
|
static options: GenerateOptions;
|
|
119
119
|
/**
|
package/dist/index.js
CHANGED
|
@@ -58,8 +58,11 @@ function getCamelName(value) {
|
|
|
58
58
|
|
|
59
59
|
// src/entities/model.ts
|
|
60
60
|
var Model = class {
|
|
61
|
+
// Model名称
|
|
61
62
|
|
|
63
|
+
// 字段列表
|
|
62
64
|
|
|
65
|
+
// 导入列表
|
|
63
66
|
|
|
64
67
|
constructor(name) {
|
|
65
68
|
this.name = name;
|
|
@@ -68,12 +71,19 @@ var Model = class {
|
|
|
68
71
|
|
|
69
72
|
// src/entities/field.ts
|
|
70
73
|
var Field = class {
|
|
74
|
+
// 字段名称
|
|
71
75
|
|
|
76
|
+
// 是否必填
|
|
72
77
|
|
|
78
|
+
// 字段类型
|
|
73
79
|
|
|
80
|
+
// 引用类型
|
|
74
81
|
|
|
82
|
+
// 字段枚举
|
|
75
83
|
|
|
84
|
+
// 描述信息
|
|
76
85
|
|
|
86
|
+
// 导入类型
|
|
77
87
|
|
|
78
88
|
constructor(name, required) {
|
|
79
89
|
this.name = name;
|
|
@@ -213,10 +223,15 @@ var Service = (_class = class {
|
|
|
213
223
|
this.name = name;
|
|
214
224
|
this.responseType = ((_b = (_a = Generate.options) == null ? void 0 : _a.exportServices) == null ? void 0 : _b.responseType) || "promise";
|
|
215
225
|
}
|
|
226
|
+
// 服务名称
|
|
216
227
|
|
|
228
|
+
// 应用名称
|
|
217
229
|
|
|
230
|
+
// 导出Model
|
|
218
231
|
__init() {this.imports = []}
|
|
232
|
+
// 操作列表
|
|
219
233
|
__init2() {this.operations = []}
|
|
234
|
+
// 返回类型
|
|
220
235
|
|
|
221
236
|
}, _class);
|
|
222
237
|
|
|
@@ -233,15 +248,25 @@ function getServiceName(path5, method, operationObject, tags) {
|
|
|
233
248
|
|
|
234
249
|
// src/entities/operation.ts
|
|
235
250
|
var Operation = (_class2 = class {
|
|
251
|
+
// Operation名称
|
|
236
252
|
|
|
253
|
+
// Operation Method
|
|
237
254
|
|
|
255
|
+
// Operation地址
|
|
238
256
|
|
|
257
|
+
// Operation注释
|
|
239
258
|
|
|
259
|
+
// response类型
|
|
240
260
|
|
|
261
|
+
// 返回类型
|
|
241
262
|
|
|
263
|
+
// Query参数
|
|
242
264
|
__init3() {this.parametersPath = []}
|
|
265
|
+
// Body参数
|
|
243
266
|
__init4() {this.parametersQuery = []}
|
|
267
|
+
// path参数
|
|
244
268
|
|
|
269
|
+
// 导入操作
|
|
245
270
|
__init5() {this.imports = []}
|
|
246
271
|
constructor(name, method, path5) {;_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);
|
|
247
272
|
var _a, _b;
|
|
@@ -265,13 +290,21 @@ function getOperationName(path5, method, operationObject) {
|
|
|
265
290
|
|
|
266
291
|
// src/entities/operation-parameter.ts
|
|
267
292
|
var OperationParameter = (_class3 = class {constructor() { _class3.prototype.__init6.call(this); }
|
|
293
|
+
// 参数位置
|
|
268
294
|
|
|
295
|
+
// 参数名称
|
|
269
296
|
|
|
297
|
+
// 参数类型
|
|
270
298
|
|
|
299
|
+
// 参数引用
|
|
271
300
|
|
|
301
|
+
// 参数枚举
|
|
272
302
|
|
|
303
|
+
// 参数注释
|
|
273
304
|
|
|
305
|
+
// 是否必填
|
|
274
306
|
|
|
307
|
+
// 导入类型
|
|
275
308
|
__init6() {this.imports = []}
|
|
276
309
|
}, _class3);
|
|
277
310
|
|
|
@@ -886,6 +919,11 @@ function writeServices(client, options) {
|
|
|
886
919
|
|
|
887
920
|
// src/generate/index.ts
|
|
888
921
|
var _Generate = class {
|
|
922
|
+
/**
|
|
923
|
+
* 生成入口
|
|
924
|
+
* @param options
|
|
925
|
+
* @returns
|
|
926
|
+
*/
|
|
889
927
|
static startup(options) {
|
|
890
928
|
_Generate.options = options;
|
|
891
929
|
registerHandlebarTemplates();
|
|
@@ -896,6 +934,9 @@ var _Generate = class {
|
|
|
896
934
|
)
|
|
897
935
|
);
|
|
898
936
|
}
|
|
937
|
+
/**
|
|
938
|
+
* 生成应用
|
|
939
|
+
*/
|
|
899
940
|
static async generateApplication(options) {
|
|
900
941
|
const document = await getOpenApiDocument(
|
|
901
942
|
options.input
|
|
@@ -904,6 +945,12 @@ var _Generate = class {
|
|
|
904
945
|
const client = _Generate.generateClient(document, version);
|
|
905
946
|
_Generate.writeClient(client, options);
|
|
906
947
|
}
|
|
948
|
+
/**
|
|
949
|
+
* 生成对象信息
|
|
950
|
+
* @param document
|
|
951
|
+
* @param version
|
|
952
|
+
* @returns
|
|
953
|
+
*/
|
|
907
954
|
static generateClient(document, version) {
|
|
908
955
|
switch (version) {
|
|
909
956
|
case 2 /* V2 */:
|
|
@@ -912,6 +959,11 @@ var _Generate = class {
|
|
|
912
959
|
return parseV3(document);
|
|
913
960
|
}
|
|
914
961
|
}
|
|
962
|
+
/**
|
|
963
|
+
* 写入Client对象
|
|
964
|
+
* @param client
|
|
965
|
+
* @param options
|
|
966
|
+
*/
|
|
915
967
|
static writeClient(client, options) {
|
|
916
968
|
writeModels(client, options);
|
|
917
969
|
writeServices(client, options);
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__dirname,
|
|
3
3
|
__publicField
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-LBEPSBX6.mjs";
|
|
5
5
|
|
|
6
6
|
// src/utils/get-openapi-document.ts
|
|
7
7
|
import swaggerParse from "@apidevtools/swagger-parser";
|
|
@@ -59,8 +59,11 @@ function getCamelName(value) {
|
|
|
59
59
|
|
|
60
60
|
// src/entities/model.ts
|
|
61
61
|
var Model = class {
|
|
62
|
+
// Model名称
|
|
62
63
|
name;
|
|
64
|
+
// 字段列表
|
|
63
65
|
fields;
|
|
66
|
+
// 导入列表
|
|
64
67
|
imports;
|
|
65
68
|
constructor(name) {
|
|
66
69
|
this.name = name;
|
|
@@ -69,12 +72,19 @@ var Model = class {
|
|
|
69
72
|
|
|
70
73
|
// src/entities/field.ts
|
|
71
74
|
var Field = class {
|
|
75
|
+
// 字段名称
|
|
72
76
|
name;
|
|
77
|
+
// 是否必填
|
|
73
78
|
required;
|
|
79
|
+
// 字段类型
|
|
74
80
|
type;
|
|
81
|
+
// 引用类型
|
|
75
82
|
ref;
|
|
83
|
+
// 字段枚举
|
|
76
84
|
enums;
|
|
85
|
+
// 描述信息
|
|
77
86
|
description;
|
|
87
|
+
// 导入类型
|
|
78
88
|
imports;
|
|
79
89
|
constructor(name, required) {
|
|
80
90
|
this.name = name;
|
|
@@ -214,10 +224,15 @@ var Service = class {
|
|
|
214
224
|
this.name = name;
|
|
215
225
|
this.responseType = ((_b = (_a = Generate.options) == null ? void 0 : _a.exportServices) == null ? void 0 : _b.responseType) || "promise";
|
|
216
226
|
}
|
|
227
|
+
// 服务名称
|
|
217
228
|
name;
|
|
229
|
+
// 应用名称
|
|
218
230
|
application;
|
|
231
|
+
// 导出Model
|
|
219
232
|
imports = [];
|
|
233
|
+
// 操作列表
|
|
220
234
|
operations = [];
|
|
235
|
+
// 返回类型
|
|
221
236
|
responseType;
|
|
222
237
|
};
|
|
223
238
|
|
|
@@ -234,15 +249,25 @@ function getServiceName(path5, method, operationObject, tags) {
|
|
|
234
249
|
|
|
235
250
|
// src/entities/operation.ts
|
|
236
251
|
var Operation = class {
|
|
252
|
+
// Operation名称
|
|
237
253
|
name;
|
|
254
|
+
// Operation Method
|
|
238
255
|
method;
|
|
256
|
+
// Operation地址
|
|
239
257
|
path;
|
|
258
|
+
// Operation注释
|
|
240
259
|
description;
|
|
260
|
+
// response类型
|
|
241
261
|
responseRef;
|
|
262
|
+
// 返回类型
|
|
242
263
|
responseType;
|
|
264
|
+
// Query参数
|
|
243
265
|
parametersPath = [];
|
|
266
|
+
// Body参数
|
|
244
267
|
parametersQuery = [];
|
|
268
|
+
// path参数
|
|
245
269
|
parametersBody;
|
|
270
|
+
// 导入操作
|
|
246
271
|
imports = [];
|
|
247
272
|
constructor(name, method, path5) {
|
|
248
273
|
var _a, _b;
|
|
@@ -266,13 +291,21 @@ function getOperationName(path5, method, operationObject) {
|
|
|
266
291
|
|
|
267
292
|
// src/entities/operation-parameter.ts
|
|
268
293
|
var OperationParameter = class {
|
|
294
|
+
// 参数位置
|
|
269
295
|
in;
|
|
296
|
+
// 参数名称
|
|
270
297
|
name;
|
|
298
|
+
// 参数类型
|
|
271
299
|
type;
|
|
300
|
+
// 参数引用
|
|
272
301
|
ref;
|
|
302
|
+
// 参数枚举
|
|
273
303
|
enums;
|
|
304
|
+
// 参数注释
|
|
274
305
|
description;
|
|
306
|
+
// 是否必填
|
|
275
307
|
required;
|
|
308
|
+
// 导入类型
|
|
276
309
|
imports = [];
|
|
277
310
|
};
|
|
278
311
|
|
|
@@ -887,6 +920,11 @@ function writeServices(client, options) {
|
|
|
887
920
|
|
|
888
921
|
// src/generate/index.ts
|
|
889
922
|
var _Generate = class {
|
|
923
|
+
/**
|
|
924
|
+
* 生成入口
|
|
925
|
+
* @param options
|
|
926
|
+
* @returns
|
|
927
|
+
*/
|
|
890
928
|
static startup(options) {
|
|
891
929
|
_Generate.options = options;
|
|
892
930
|
registerHandlebarTemplates();
|
|
@@ -897,6 +935,9 @@ var _Generate = class {
|
|
|
897
935
|
)
|
|
898
936
|
);
|
|
899
937
|
}
|
|
938
|
+
/**
|
|
939
|
+
* 生成应用
|
|
940
|
+
*/
|
|
900
941
|
static async generateApplication(options) {
|
|
901
942
|
const document = await getOpenApiDocument(
|
|
902
943
|
options.input
|
|
@@ -905,6 +946,12 @@ var _Generate = class {
|
|
|
905
946
|
const client = _Generate.generateClient(document, version);
|
|
906
947
|
_Generate.writeClient(client, options);
|
|
907
948
|
}
|
|
949
|
+
/**
|
|
950
|
+
* 生成对象信息
|
|
951
|
+
* @param document
|
|
952
|
+
* @param version
|
|
953
|
+
* @returns
|
|
954
|
+
*/
|
|
908
955
|
static generateClient(document, version) {
|
|
909
956
|
switch (version) {
|
|
910
957
|
case 2 /* V2 */:
|
|
@@ -913,6 +960,11 @@ var _Generate = class {
|
|
|
913
960
|
return parseV3(document);
|
|
914
961
|
}
|
|
915
962
|
}
|
|
963
|
+
/**
|
|
964
|
+
* 写入Client对象
|
|
965
|
+
* @param client
|
|
966
|
+
* @param options
|
|
967
|
+
*/
|
|
916
968
|
static writeClient(client, options) {
|
|
917
969
|
writeModels(client, options);
|
|
918
970
|
writeServices(client, options);
|
|
@@ -3,6 +3,34 @@ export class {{{name}}}Service {
|
|
|
3
3
|
private request = RequestService.getInstance();
|
|
4
4
|
private service = '{{{application}}}'
|
|
5
5
|
|
|
6
|
+
private generateRequest(
|
|
7
|
+
requestSendOptions: RequestSendOptions,
|
|
8
|
+
requestPlugins: RequestPlugin[] = [],
|
|
9
|
+
requestGenerateOptions?: RequestGenerateOptions
|
|
10
|
+
){
|
|
11
|
+
switch(true){
|
|
12
|
+
case requestGenerateOptions?.type === RequestGenerateType.URL:
|
|
13
|
+
// 生成URL
|
|
14
|
+
return this.request.toURL(
|
|
15
|
+
requestSendOptions,
|
|
16
|
+
requestPlugins
|
|
17
|
+
);
|
|
18
|
+
default: {
|
|
19
|
+
// 请求数据
|
|
20
|
+
const result = this.request.send(
|
|
21
|
+
requestSendOptions,
|
|
22
|
+
requestPlugins
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
{{#equal responseType 'observable'}}
|
|
26
|
+
return from(result)
|
|
27
|
+
{{else}}
|
|
28
|
+
return result
|
|
29
|
+
{{/equal}}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
6
34
|
{{#each operations}}
|
|
7
35
|
{{>export-service-operation}}
|
|
8
36
|
{{/each}}
|
|
@@ -6,4 +6,4 @@ import type { {{{this}}} } from '../models/{{{this}}}';
|
|
|
6
6
|
{{#equal responseType 'observable'}}
|
|
7
7
|
import { from, type Observable } from 'rxjs';
|
|
8
8
|
{{/equal}}
|
|
9
|
-
import { RequestService, type RequestPlugin } from '@gopowerteam/request';
|
|
9
|
+
import { RequestService, RequestGenerateType, type RequestSendOptions, type RequestPlugin, type RequestGenerateOptions } from '@gopowerteam/request';
|
|
@@ -3,35 +3,48 @@ public {{{name}}}(
|
|
|
3
3
|
{{>export-operation-params-path}}
|
|
4
4
|
{{>export-operation-params-query}}
|
|
5
5
|
{{>export-operation-params-body}}
|
|
6
|
-
requestPlugins: RequestPlugin[]
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
6
|
+
requestPlugins: RequestPlugin[],
|
|
7
|
+
requestGenerateOptions: RequestGenerateOptions & { type: RequestGenerateType.URL }
|
|
8
|
+
): string
|
|
9
|
+
public {{{name}}}(
|
|
10
|
+
{{>export-operation-params-path}}
|
|
11
|
+
{{>export-operation-params-query}}
|
|
12
|
+
{{>export-operation-params-body}}
|
|
13
|
+
requestPlugins?: RequestPlugin[],
|
|
14
|
+
requestGenerateOptions?: RequestGenerateOptions
|
|
15
|
+
): {{>export-operation-response }}
|
|
16
|
+
public {{{name}}}(
|
|
17
|
+
{{>export-operation-params-path}}
|
|
18
|
+
{{>export-operation-params-query}}
|
|
19
|
+
{{>export-operation-params-body}}
|
|
20
|
+
requestPlugins: RequestPlugin[] = [],
|
|
21
|
+
requestGenerateOptions?: RequestGenerateOptions
|
|
22
|
+
): {{>export-operation-response }} | string {
|
|
23
|
+
const requestSendOptions = {
|
|
24
|
+
service: this.service,
|
|
25
|
+
path: '{{{path}}}',
|
|
26
|
+
method: '{{{method}}}',
|
|
27
|
+
{{#if parametersPath}}
|
|
28
|
+
paramsPath: {
|
|
29
|
+
{{#each parametersPath}}
|
|
30
|
+
{{{name}}},
|
|
31
|
+
{{/each}}
|
|
27
32
|
},
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
{{/if}}
|
|
34
|
+
{{#if parametersQuery}}
|
|
35
|
+
paramsQuery: requestQuery,
|
|
36
|
+
{{/if}}
|
|
37
|
+
{{#if parametersBody}}
|
|
38
|
+
paramsBody: requestBody,
|
|
39
|
+
{{/if}}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return this.generateRequest(
|
|
43
|
+
requestSendOptions,
|
|
44
|
+
requestPlugins,
|
|
45
|
+
requestGenerateOptions
|
|
46
|
+
)
|
|
47
|
+
|
|
30
48
|
|
|
31
|
-
{{#equal responseType 'observable'}}
|
|
32
|
-
return from(result)
|
|
33
|
-
{{else}}
|
|
34
|
-
return result
|
|
35
|
-
{{/equal}}
|
|
36
49
|
}
|
|
37
50
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gopowerteam/request-generate",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.13",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
@@ -32,27 +32,27 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@
|
|
36
|
-
"@types/
|
|
37
|
-
"@types/node": "16",
|
|
35
|
+
"@types/jest": "^29.4.0",
|
|
36
|
+
"@types/node": "18",
|
|
38
37
|
"@types/qs": "^6.9.7",
|
|
39
38
|
"@types/rimraf": "^3.0.2",
|
|
40
|
-
"commander": "^
|
|
41
|
-
"fs-extra": "^
|
|
42
|
-
"jest": "^29.
|
|
43
|
-
"openapi-types": "^12.0
|
|
44
|
-
"ts-jest": "^29.0.
|
|
39
|
+
"commander": "^10.0.0",
|
|
40
|
+
"fs-extra": "^11.1.0",
|
|
41
|
+
"jest": "^29.4.3",
|
|
42
|
+
"openapi-types": "^12.1.0",
|
|
43
|
+
"ts-jest": "^29.0.5",
|
|
45
44
|
"ts-node": "^10.9.1",
|
|
46
|
-
"tsup": "^6.
|
|
47
|
-
"typescript": "^4.
|
|
48
|
-
"vite": "^
|
|
45
|
+
"tsup": "^6.6.3",
|
|
46
|
+
"typescript": "^4.9.5",
|
|
47
|
+
"vite": "^4.1.4",
|
|
48
|
+
"@gopowerteam/request": "0.1.12"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@apidevtools/swagger-parser": "^10.1.0",
|
|
52
52
|
"handlebars": "^4.7.7",
|
|
53
53
|
"qs": "^6.11.0",
|
|
54
|
-
"rimraf": "^
|
|
55
|
-
"rxjs": "^7.
|
|
54
|
+
"rimraf": "^4.1.2",
|
|
55
|
+
"rxjs": "^7.8.0"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "tsup"
|