@gopowerteam/request-generate 0.1.7 → 0.1.9
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
|
};
|
|
@@ -204,6 +208,7 @@ var Service = (_class = class {
|
|
|
204
208
|
this.responseType = ((_b = (_a = Generate.options) == null ? void 0 : _a.exportServices) == null ? void 0 : _b.responseType) || "promise";
|
|
205
209
|
}
|
|
206
210
|
|
|
211
|
+
|
|
207
212
|
__init() {this.imports = []}
|
|
208
213
|
__init2() {this.operations = []}
|
|
209
214
|
|
|
@@ -618,14 +623,25 @@ function parseOperation2(path5, method, operationObject) {
|
|
|
618
623
|
return operation;
|
|
619
624
|
}
|
|
620
625
|
function parseResponseType2(responses) {
|
|
621
|
-
var _a, _b
|
|
626
|
+
var _a, _b;
|
|
622
627
|
const SUCCESS_STATUS_CODE = "200";
|
|
623
628
|
const response = responses == null ? void 0 : responses[SUCCESS_STATUS_CODE];
|
|
629
|
+
const medias = ["*/*", "application/json"];
|
|
624
630
|
if (response && "$ref" in response) {
|
|
625
631
|
return parseSchemaType2(responses);
|
|
626
632
|
}
|
|
627
|
-
if (response && "content" in response && ((
|
|
628
|
-
|
|
633
|
+
if (response && "content" in response && medias.some((media) => {
|
|
634
|
+
var _a2, _b2;
|
|
635
|
+
return !!((_b2 = (_a2 = response == null ? void 0 : response.content) == null ? void 0 : _a2[media]) == null ? void 0 : _b2.schema);
|
|
636
|
+
})) {
|
|
637
|
+
const mediaType = medias.find(
|
|
638
|
+
(media) => {
|
|
639
|
+
var _a2, _b2;
|
|
640
|
+
return !!((_b2 = (_a2 = response == null ? void 0 : response.content) == null ? void 0 : _a2[media]) == null ? void 0 : _b2.schema);
|
|
641
|
+
}
|
|
642
|
+
);
|
|
643
|
+
const schema = (_b = (_a = response == null ? void 0 : response.content) == null ? void 0 : _a[mediaType]) == null ? void 0 : _b.schema;
|
|
644
|
+
return parseSchemaType2(schema);
|
|
629
645
|
}
|
|
630
646
|
return {
|
|
631
647
|
type: "void",
|
|
@@ -852,6 +868,7 @@ function writeServices(client, options) {
|
|
|
852
868
|
fs4.mkdirSync(output, { recursive: true });
|
|
853
869
|
client.services.forEach((service) => {
|
|
854
870
|
const filename = `${service.name}Service.ts`;
|
|
871
|
+
service.application = options.application;
|
|
855
872
|
writeService(service, path4.join(output, filename));
|
|
856
873
|
});
|
|
857
874
|
}
|
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
|
};
|
|
@@ -205,6 +209,7 @@ var Service = class {
|
|
|
205
209
|
this.responseType = ((_b = (_a = Generate.options) == null ? void 0 : _a.exportServices) == null ? void 0 : _b.responseType) || "promise";
|
|
206
210
|
}
|
|
207
211
|
name;
|
|
212
|
+
application;
|
|
208
213
|
imports = [];
|
|
209
214
|
operations = [];
|
|
210
215
|
responseType;
|
|
@@ -619,14 +624,25 @@ function parseOperation2(path5, method, operationObject) {
|
|
|
619
624
|
return operation;
|
|
620
625
|
}
|
|
621
626
|
function parseResponseType2(responses) {
|
|
622
|
-
var _a, _b
|
|
627
|
+
var _a, _b;
|
|
623
628
|
const SUCCESS_STATUS_CODE = "200";
|
|
624
629
|
const response = responses == null ? void 0 : responses[SUCCESS_STATUS_CODE];
|
|
630
|
+
const medias = ["*/*", "application/json"];
|
|
625
631
|
if (response && "$ref" in response) {
|
|
626
632
|
return parseSchemaType2(responses);
|
|
627
633
|
}
|
|
628
|
-
if (response && "content" in response && ((
|
|
629
|
-
|
|
634
|
+
if (response && "content" in response && medias.some((media) => {
|
|
635
|
+
var _a2, _b2;
|
|
636
|
+
return !!((_b2 = (_a2 = response == null ? void 0 : response.content) == null ? void 0 : _a2[media]) == null ? void 0 : _b2.schema);
|
|
637
|
+
})) {
|
|
638
|
+
const mediaType = medias.find(
|
|
639
|
+
(media) => {
|
|
640
|
+
var _a2, _b2;
|
|
641
|
+
return !!((_b2 = (_a2 = response == null ? void 0 : response.content) == null ? void 0 : _a2[media]) == null ? void 0 : _b2.schema);
|
|
642
|
+
}
|
|
643
|
+
);
|
|
644
|
+
const schema = (_b = (_a = response == null ? void 0 : response.content) == null ? void 0 : _a[mediaType]) == null ? void 0 : _b.schema;
|
|
645
|
+
return parseSchemaType2(schema);
|
|
630
646
|
}
|
|
631
647
|
return {
|
|
632
648
|
type: "void",
|
|
@@ -853,6 +869,7 @@ function writeServices(client, options) {
|
|
|
853
869
|
fs4.mkdirSync(output, { recursive: true });
|
|
854
870
|
client.services.forEach((service) => {
|
|
855
871
|
const filename = `${service.name}Service.ts`;
|
|
872
|
+
service.application = options.application;
|
|
856
873
|
writeService(service, path4.join(output, filename));
|
|
857
874
|
});
|
|
858
875
|
}
|