@gopowerteam/request-generate 0.1.8 → 0.1.10
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/index.d.ts
CHANGED
|
@@ -43,6 +43,8 @@ type GenerateApplicationOptions = Pick<
|
|
|
43
43
|
> & {
|
|
44
44
|
// 服务名称
|
|
45
45
|
name?: string
|
|
46
|
+
// 应用名称
|
|
47
|
+
application?: string
|
|
46
48
|
// OPENAPI地址
|
|
47
49
|
input: string
|
|
48
50
|
}
|
|
@@ -98,6 +100,7 @@ declare class Operation {
|
|
|
98
100
|
declare class Service {
|
|
99
101
|
constructor(name: string);
|
|
100
102
|
name: string;
|
|
103
|
+
application?: string;
|
|
101
104
|
imports: string[];
|
|
102
105
|
operations: Operation[];
|
|
103
106
|
responseType: 'promise' | 'observable';
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,11 @@ var _path = require('path'); var path2 = _interopRequireWildcard(_path); var pat
|
|
|
32
32
|
function createOptions(options, name, application = "") {
|
|
33
33
|
return {
|
|
34
34
|
name,
|
|
35
|
-
|
|
35
|
+
application,
|
|
36
|
+
input: `${options.gateway}/${application}/${options.openapi}`.replace(
|
|
37
|
+
/\/{2,3}/g,
|
|
38
|
+
"/"
|
|
39
|
+
),
|
|
36
40
|
output: name ? path2.default.join(options.output, name) : options.output,
|
|
37
41
|
exportModels: options.exportModels
|
|
38
42
|
};
|
|
@@ -143,6 +147,12 @@ function parseSchemaType(schema) {
|
|
|
143
147
|
ref: void 0
|
|
144
148
|
};
|
|
145
149
|
}
|
|
150
|
+
if (!("$ref" in schema) && schema.type === "object") {
|
|
151
|
+
return {
|
|
152
|
+
type: getMappedType(schema.type),
|
|
153
|
+
ref: "any"
|
|
154
|
+
};
|
|
155
|
+
}
|
|
146
156
|
throw new Error("\u65E0\u6CD5\u89E3\u6790\u76F8\u5E94\u7684schema");
|
|
147
157
|
}
|
|
148
158
|
|
|
@@ -204,6 +214,7 @@ var Service = (_class = class {
|
|
|
204
214
|
this.responseType = ((_b = (_a = Generate.options) == null ? void 0 : _a.exportServices) == null ? void 0 : _b.responseType) || "promise";
|
|
205
215
|
}
|
|
206
216
|
|
|
217
|
+
|
|
207
218
|
__init() {this.imports = []}
|
|
208
219
|
__init2() {this.operations = []}
|
|
209
220
|
|
|
@@ -322,6 +333,11 @@ function parseParametersQuery(parameters) {
|
|
|
322
333
|
parameter.required = p.required;
|
|
323
334
|
parameter.imports = imports || [];
|
|
324
335
|
parameter.enums = enums;
|
|
336
|
+
if (p.name.includes(".") && !p.name.startsWith(".") && !p.name.endsWith(".")) {
|
|
337
|
+
const [name, subName] = p.name.split(".");
|
|
338
|
+
parameter.name = name;
|
|
339
|
+
parameter.ref = `{ ${subName}${parameter.required ? "?" : ""}: ${ref || "any"} }`;
|
|
340
|
+
}
|
|
325
341
|
r.push(parameter);
|
|
326
342
|
}
|
|
327
343
|
return r;
|
|
@@ -863,6 +879,7 @@ function writeServices(client, options) {
|
|
|
863
879
|
fs4.mkdirSync(output, { recursive: true });
|
|
864
880
|
client.services.forEach((service) => {
|
|
865
881
|
const filename = `${service.name}Service.ts`;
|
|
882
|
+
service.application = options.application;
|
|
866
883
|
writeService(service, path4.join(output, filename));
|
|
867
884
|
});
|
|
868
885
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -33,7 +33,11 @@ import path from "node:path";
|
|
|
33
33
|
function createOptions(options, name, application = "") {
|
|
34
34
|
return {
|
|
35
35
|
name,
|
|
36
|
-
|
|
36
|
+
application,
|
|
37
|
+
input: `${options.gateway}/${application}/${options.openapi}`.replace(
|
|
38
|
+
/\/{2,3}/g,
|
|
39
|
+
"/"
|
|
40
|
+
),
|
|
37
41
|
output: name ? path.join(options.output, name) : options.output,
|
|
38
42
|
exportModels: options.exportModels
|
|
39
43
|
};
|
|
@@ -144,6 +148,12 @@ function parseSchemaType(schema) {
|
|
|
144
148
|
ref: void 0
|
|
145
149
|
};
|
|
146
150
|
}
|
|
151
|
+
if (!("$ref" in schema) && schema.type === "object") {
|
|
152
|
+
return {
|
|
153
|
+
type: getMappedType(schema.type),
|
|
154
|
+
ref: "any"
|
|
155
|
+
};
|
|
156
|
+
}
|
|
147
157
|
throw new Error("\u65E0\u6CD5\u89E3\u6790\u76F8\u5E94\u7684schema");
|
|
148
158
|
}
|
|
149
159
|
|
|
@@ -205,6 +215,7 @@ var Service = class {
|
|
|
205
215
|
this.responseType = ((_b = (_a = Generate.options) == null ? void 0 : _a.exportServices) == null ? void 0 : _b.responseType) || "promise";
|
|
206
216
|
}
|
|
207
217
|
name;
|
|
218
|
+
application;
|
|
208
219
|
imports = [];
|
|
209
220
|
operations = [];
|
|
210
221
|
responseType;
|
|
@@ -323,6 +334,11 @@ function parseParametersQuery(parameters) {
|
|
|
323
334
|
parameter.required = p.required;
|
|
324
335
|
parameter.imports = imports || [];
|
|
325
336
|
parameter.enums = enums;
|
|
337
|
+
if (p.name.includes(".") && !p.name.startsWith(".") && !p.name.endsWith(".")) {
|
|
338
|
+
const [name, subName] = p.name.split(".");
|
|
339
|
+
parameter.name = name;
|
|
340
|
+
parameter.ref = `{ ${subName}${parameter.required ? "?" : ""}: ${ref || "any"} }`;
|
|
341
|
+
}
|
|
326
342
|
r.push(parameter);
|
|
327
343
|
}
|
|
328
344
|
return r;
|
|
@@ -864,6 +880,7 @@ function writeServices(client, options) {
|
|
|
864
880
|
fs4.mkdirSync(output, { recursive: true });
|
|
865
881
|
client.services.forEach((service) => {
|
|
866
882
|
const filename = `${service.name}Service.ts`;
|
|
883
|
+
service.application = options.application;
|
|
867
884
|
writeService(service, path4.join(output, filename));
|
|
868
885
|
});
|
|
869
886
|
}
|