@ahoo-wang/fetcher-generator 2.5.2 → 2.5.5
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/aggregate/aggregateResolver.d.ts.map +1 -1
- package/dist/aggregate/index.d.ts +1 -1
- package/dist/aggregate/utils.d.ts +1 -1
- package/dist/aggregate/utils.d.ts.map +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +25 -26
- package/dist/cli.js.map +1 -1
- package/dist/client/apiClientGenerator.d.ts.map +1 -1
- package/dist/client/commandClientGenerator.d.ts +1 -1
- package/dist/client/commandClientGenerator.d.ts.map +1 -1
- package/dist/client/decorators.d.ts +5 -0
- package/dist/client/decorators.d.ts.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/queryClientGenerator.d.ts +1 -1
- package/dist/client/queryClientGenerator.d.ts.map +1 -1
- package/dist/generateContext.d.ts +2 -2
- package/dist/generateContext.d.ts.map +1 -1
- package/dist/index.cjs +8 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +740 -749
- package/dist/index.js.map +1 -1
- package/dist/model/modelGenerator.d.ts +1 -1
- package/dist/model/modelGenerator.d.ts.map +1 -1
- package/dist/model/modelInfo.d.ts +1 -1
- package/dist/model/modelInfo.d.ts.map +1 -1
- package/dist/types.d.ts +1 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/clis.d.ts +1 -0
- package/dist/utils/clis.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/parsers.d.ts.map +1 -1
- package/dist/utils/responses.d.ts +1 -1
- package/dist/utils/responses.d.ts.map +1 -1
- package/dist/utils/sourceFiles.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,48 +1,17 @@
|
|
|
1
|
+
import { Scope as ae, VariableDeclarationKind as v, Project as ce } from "ts-morph";
|
|
1
2
|
import { ContentTypeValues as S, combineURLs as w } from "@ahoo-wang/fetcher";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { join as ge, relative as le } from "path";
|
|
7
|
-
function pe(r) {
|
|
8
|
-
const e = r.split(".");
|
|
9
|
-
return e.length != 2 || e[0].length === 0 || e[1].length === 0 ? null : e;
|
|
10
|
-
}
|
|
11
|
-
function ue(r) {
|
|
12
|
-
const e = pe(r.name);
|
|
13
|
-
return e ? {
|
|
14
|
-
tag: r,
|
|
15
|
-
contextAlias: e[0],
|
|
16
|
-
aggregateName: e[1]
|
|
17
|
-
} : null;
|
|
18
|
-
}
|
|
19
|
-
function me(r) {
|
|
20
|
-
const e = r?.map((n) => ue(n)).filter((n) => n !== null);
|
|
21
|
-
if (!e)
|
|
22
|
-
return /* @__PURE__ */ new Map();
|
|
23
|
-
const t = /* @__PURE__ */ new Map();
|
|
24
|
-
return e.forEach((n) => {
|
|
25
|
-
t.set(n.tag.name, {
|
|
26
|
-
aggregate: n,
|
|
27
|
-
commands: /* @__PURE__ */ new Map(),
|
|
28
|
-
events: /* @__PURE__ */ new Map()
|
|
29
|
-
});
|
|
30
|
-
}), t;
|
|
31
|
-
}
|
|
32
|
-
function de(r) {
|
|
33
|
-
if (!r)
|
|
34
|
-
return null;
|
|
35
|
-
const e = r.split(".");
|
|
36
|
-
return e.length != 3 ? null : e[2];
|
|
37
|
-
}
|
|
3
|
+
import { ResourceAttributionPathSpec as F } from "@ahoo-wang/fetcher-wow";
|
|
4
|
+
import { parse as k } from "yaml";
|
|
5
|
+
import { readFile as ge } from "fs";
|
|
6
|
+
import { join as le, relative as pe } from "path";
|
|
38
7
|
function $(r) {
|
|
39
8
|
return r.$ref.split("/").pop();
|
|
40
9
|
}
|
|
41
|
-
function
|
|
10
|
+
function E(r, e) {
|
|
42
11
|
const t = $(r);
|
|
43
12
|
return e.schemas?.[t];
|
|
44
13
|
}
|
|
45
|
-
function
|
|
14
|
+
function L(r, e) {
|
|
46
15
|
const t = $(r);
|
|
47
16
|
return e.requestBodies?.[t];
|
|
48
17
|
}
|
|
@@ -53,11 +22,11 @@ function Q(r, e) {
|
|
|
53
22
|
function T(r, e) {
|
|
54
23
|
return {
|
|
55
24
|
key: $(r),
|
|
56
|
-
schema:
|
|
25
|
+
schema: E(r, e)
|
|
57
26
|
};
|
|
58
27
|
}
|
|
59
28
|
const G = /[-_\s.]+/;
|
|
60
|
-
function
|
|
29
|
+
function U(r) {
|
|
61
30
|
return Array.isArray(r) ? r.flatMap((e) => _(e.split(G))) : _(r.split(G));
|
|
62
31
|
}
|
|
63
32
|
function _(r) {
|
|
@@ -74,7 +43,7 @@ function _(r) {
|
|
|
74
43
|
});
|
|
75
44
|
}
|
|
76
45
|
function A(r) {
|
|
77
|
-
return r === "" || r.length === 0 ? "" :
|
|
46
|
+
return r === "" || r.length === 0 ? "" : U(r).filter((t) => t.length > 0).map((t) => {
|
|
78
47
|
const n = t.charAt(0), o = t.slice(1);
|
|
79
48
|
return (/[a-zA-Z]/.test(n) ? n.toUpperCase() : n) + o.toLowerCase();
|
|
80
49
|
}).join("");
|
|
@@ -83,109 +52,60 @@ function h(r) {
|
|
|
83
52
|
const e = A(r);
|
|
84
53
|
return e.charAt(0).toLowerCase() + e.slice(1);
|
|
85
54
|
}
|
|
86
|
-
function
|
|
87
|
-
return r === "" || Array.isArray(r) && r.length === 0 ? "" :
|
|
88
|
-
}
|
|
89
|
-
function U(r) {
|
|
90
|
-
return r.startsWith("http://") || r.startsWith("https://") ? he(r) : ye(r);
|
|
91
|
-
}
|
|
92
|
-
async function he(r) {
|
|
93
|
-
return await (await fetch(r)).text();
|
|
94
|
-
}
|
|
95
|
-
function ye(r) {
|
|
96
|
-
return new Promise((e, t) => {
|
|
97
|
-
ce(r, "utf-8", (n, o) => {
|
|
98
|
-
n ? t(n) : e(o);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
async function xe(r) {
|
|
103
|
-
const e = await U(r);
|
|
104
|
-
switch (J(e)) {
|
|
105
|
-
case "json":
|
|
106
|
-
return JSON.parse(e);
|
|
107
|
-
case "yaml":
|
|
108
|
-
return B(e);
|
|
109
|
-
default:
|
|
110
|
-
throw new Error(`Unsupported file format: ${r}`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
async function Ae(r) {
|
|
114
|
-
const e = await U(r);
|
|
115
|
-
switch (J(e)) {
|
|
116
|
-
case "json":
|
|
117
|
-
return JSON.parse(e);
|
|
118
|
-
case "yaml":
|
|
119
|
-
return B(e);
|
|
120
|
-
default:
|
|
121
|
-
throw new Error(`Unsupported file format: ${r}`);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
function J(r) {
|
|
125
|
-
const e = r.trimStart();
|
|
126
|
-
if (e.startsWith("{") || e.startsWith("["))
|
|
127
|
-
return "json";
|
|
128
|
-
if (e.startsWith("-") || e.startsWith("%YAML"))
|
|
129
|
-
return "yaml";
|
|
130
|
-
try {
|
|
131
|
-
return JSON.parse(e), "json";
|
|
132
|
-
} catch {
|
|
133
|
-
if (e.length > 0)
|
|
134
|
-
return "yaml";
|
|
135
|
-
}
|
|
136
|
-
throw new Error("Unable to infer file format");
|
|
55
|
+
function ue(r) {
|
|
56
|
+
return r === "" || Array.isArray(r) && r.length === 0 ? "" : U(r).filter((t) => t.length > 0).map((t) => t.toUpperCase()).join("_");
|
|
137
57
|
}
|
|
138
|
-
function
|
|
58
|
+
function g(r) {
|
|
139
59
|
return !!(r && typeof r == "object" && "$ref" in r);
|
|
140
60
|
}
|
|
141
|
-
function
|
|
142
|
-
if (e && !
|
|
61
|
+
function b(r, e) {
|
|
62
|
+
if (e && !g(e) && e.content)
|
|
143
63
|
return e.content[r]?.schema;
|
|
144
64
|
}
|
|
145
|
-
function
|
|
146
|
-
return
|
|
65
|
+
function J(r) {
|
|
66
|
+
return b(S.APPLICATION_JSON, r);
|
|
147
67
|
}
|
|
148
|
-
function
|
|
149
|
-
return
|
|
68
|
+
function me(r) {
|
|
69
|
+
return b(S.TEXT_EVENT_STREAM, r);
|
|
150
70
|
}
|
|
151
|
-
function
|
|
152
|
-
return
|
|
71
|
+
function de(r) {
|
|
72
|
+
return b("*/*", r);
|
|
153
73
|
}
|
|
154
|
-
const
|
|
74
|
+
const fe = [
|
|
155
75
|
"string",
|
|
156
76
|
"number",
|
|
157
77
|
"integer",
|
|
158
78
|
"boolean",
|
|
159
79
|
"null"
|
|
160
80
|
];
|
|
161
|
-
function
|
|
162
|
-
return Array.isArray(r) ? !0 :
|
|
81
|
+
function q(r) {
|
|
82
|
+
return Array.isArray(r) ? !0 : fe.includes(r);
|
|
163
83
|
}
|
|
164
84
|
function O(r) {
|
|
165
85
|
return r.type === "array";
|
|
166
86
|
}
|
|
167
|
-
function
|
|
87
|
+
function he(r) {
|
|
168
88
|
return Array.isArray(r.enum) && r.enum.length > 0;
|
|
169
89
|
}
|
|
170
|
-
function
|
|
90
|
+
function V(r) {
|
|
171
91
|
return Array.isArray(r.anyOf) && r.anyOf.length > 0;
|
|
172
92
|
}
|
|
173
|
-
function
|
|
93
|
+
function K(r) {
|
|
174
94
|
return Array.isArray(r.oneOf) && r.oneOf.length > 0;
|
|
175
95
|
}
|
|
176
|
-
function
|
|
177
|
-
return
|
|
96
|
+
function ye(r) {
|
|
97
|
+
return V(r) || K(r);
|
|
178
98
|
}
|
|
179
|
-
function
|
|
99
|
+
function xe(r) {
|
|
180
100
|
return Array.isArray(r.allOf) && r.allOf.length > 0;
|
|
181
101
|
}
|
|
182
|
-
function F(r) {
|
|
183
|
-
return K(r) || H(r) || Se(r);
|
|
184
|
-
}
|
|
185
102
|
function W(r) {
|
|
103
|
+
return V(r) || K(r) || xe(r);
|
|
104
|
+
}
|
|
105
|
+
function z(r) {
|
|
186
106
|
return r.includes("|") || r.includes("&") ? `(${r})[]` : `${r}[]`;
|
|
187
107
|
}
|
|
188
|
-
function
|
|
108
|
+
function Ae(r) {
|
|
189
109
|
return r.type !== "object" ? !1 : r.properties ? Object.keys(r.properties).length === 0 : !0;
|
|
190
110
|
}
|
|
191
111
|
function C(r) {
|
|
@@ -205,7 +125,7 @@ function C(r) {
|
|
|
205
125
|
return "any";
|
|
206
126
|
}
|
|
207
127
|
}
|
|
208
|
-
function
|
|
128
|
+
function H(r) {
|
|
209
129
|
return [
|
|
210
130
|
{ method: "get", operation: r.get },
|
|
211
131
|
{ method: "put", operation: r.put },
|
|
@@ -217,31 +137,80 @@ function Y(r) {
|
|
|
217
137
|
{ method: "trace", operation: r.trace }
|
|
218
138
|
].filter(({ operation: e }) => e !== void 0);
|
|
219
139
|
}
|
|
220
|
-
function
|
|
140
|
+
function M(r) {
|
|
221
141
|
return r.responses[200];
|
|
222
142
|
}
|
|
223
|
-
function
|
|
224
|
-
const e =
|
|
225
|
-
return
|
|
143
|
+
function B(r) {
|
|
144
|
+
const e = M(r);
|
|
145
|
+
return J(e);
|
|
226
146
|
}
|
|
227
|
-
function
|
|
228
|
-
return r.parameters ? r.parameters.map((t) =>
|
|
147
|
+
function Ce(r, e) {
|
|
148
|
+
return r.parameters ? r.parameters.map((t) => g(t) ? Q(t, e) : t).filter((t) => t.in === "path") : [];
|
|
149
|
+
}
|
|
150
|
+
const Pe = "string";
|
|
151
|
+
function Y(r) {
|
|
152
|
+
return !r.schema || g(r.schema) || !r.schema.type || !q(r.schema.type) ? Pe : C(r.schema.type);
|
|
229
153
|
}
|
|
230
|
-
const Ee = "string";
|
|
231
154
|
function X(r) {
|
|
232
|
-
return
|
|
155
|
+
return r.startsWith("http://") || r.startsWith("https://") ? $e(r) : Te(r);
|
|
233
156
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
157
|
+
async function $e(r) {
|
|
158
|
+
return await (await fetch(r)).text();
|
|
159
|
+
}
|
|
160
|
+
function Te(r) {
|
|
161
|
+
return new Promise((e, t) => {
|
|
162
|
+
ge(r, "utf-8", (n, o) => {
|
|
163
|
+
n ? t(n) : e(o);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
async function Ie(r) {
|
|
168
|
+
const e = await X(r);
|
|
169
|
+
switch (Z(e)) {
|
|
170
|
+
case "json":
|
|
171
|
+
return JSON.parse(e);
|
|
172
|
+
case "yaml":
|
|
173
|
+
return k(e);
|
|
174
|
+
default:
|
|
175
|
+
throw new Error(`Unsupported file format: ${r}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
async function Se(r) {
|
|
179
|
+
const e = await X(r);
|
|
180
|
+
switch (Z(e)) {
|
|
181
|
+
case "json":
|
|
182
|
+
return JSON.parse(e);
|
|
183
|
+
case "yaml":
|
|
184
|
+
return k(e);
|
|
185
|
+
default:
|
|
186
|
+
throw new Error(`Unsupported file format: ${r}`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function Z(r) {
|
|
190
|
+
const e = r.trimStart();
|
|
191
|
+
if (e.startsWith("{") || e.startsWith("["))
|
|
192
|
+
return "json";
|
|
193
|
+
if (e.startsWith("-") || e.startsWith("%YAML"))
|
|
194
|
+
return "yaml";
|
|
195
|
+
try {
|
|
196
|
+
return JSON.parse(e), "json";
|
|
197
|
+
} catch {
|
|
198
|
+
if (e.length > 0)
|
|
199
|
+
return "yaml";
|
|
200
|
+
}
|
|
201
|
+
throw new Error("Unable to infer file format");
|
|
237
202
|
}
|
|
238
|
-
|
|
203
|
+
const ee = "types.ts", we = "@";
|
|
204
|
+
function Ee(r) {
|
|
205
|
+
return w(r.path, ee);
|
|
206
|
+
}
|
|
207
|
+
function te(r, e, t) {
|
|
239
208
|
const n = w(e, t), o = r.getSourceFile(n);
|
|
240
209
|
return o || r.createSourceFile(n, "", {
|
|
241
210
|
overwrite: !0
|
|
242
211
|
});
|
|
243
212
|
}
|
|
244
|
-
function
|
|
213
|
+
function R(r, e, t) {
|
|
245
214
|
let n = r.getImportDeclaration(
|
|
246
215
|
(o) => o.getModuleSpecifierValue() === e
|
|
247
216
|
);
|
|
@@ -254,18 +223,18 @@ function E(r, e, t) {
|
|
|
254
223
|
});
|
|
255
224
|
}
|
|
256
225
|
function f(r, e, t) {
|
|
257
|
-
if (t.path.startsWith(
|
|
258
|
-
|
|
226
|
+
if (t.path.startsWith(we)) {
|
|
227
|
+
R(r, t.path, [t.name]);
|
|
259
228
|
return;
|
|
260
229
|
}
|
|
261
|
-
const n = r.getDirectoryPath(), o =
|
|
262
|
-
let s =
|
|
263
|
-
s = s.replace(/\.ts$/, ""), s.startsWith(".") || (s = "./" + s),
|
|
230
|
+
const n = r.getDirectoryPath(), o = le(e, t.path, ee);
|
|
231
|
+
let s = pe(n, o);
|
|
232
|
+
s = s.replace(/\.ts$/, ""), s.startsWith(".") || (s = "./" + s), R(r, s, [t.name]);
|
|
264
233
|
}
|
|
265
234
|
function I(r, e, t, n) {
|
|
266
235
|
r.path !== n.path && f(e, t, n);
|
|
267
236
|
}
|
|
268
|
-
function
|
|
237
|
+
function Re(r, e) {
|
|
269
238
|
const t = [r, e].filter(
|
|
270
239
|
(n) => n !== void 0 && n.length > 0
|
|
271
240
|
);
|
|
@@ -273,19 +242,50 @@ function Ne(r, e) {
|
|
|
273
242
|
`) : void 0;
|
|
274
243
|
}
|
|
275
244
|
function x(r, e, t) {
|
|
276
|
-
const n =
|
|
245
|
+
const n = Re(e, t);
|
|
277
246
|
n && r.addJsDoc({
|
|
278
247
|
description: n
|
|
279
248
|
});
|
|
280
249
|
}
|
|
281
|
-
|
|
282
|
-
|
|
250
|
+
function ve(r) {
|
|
251
|
+
const e = r.split(".");
|
|
252
|
+
return e.length != 2 || e[0].length === 0 || e[1].length === 0 ? null : e;
|
|
253
|
+
}
|
|
254
|
+
function Oe(r) {
|
|
255
|
+
const e = ve(r.name);
|
|
256
|
+
return e ? {
|
|
257
|
+
tag: r,
|
|
258
|
+
contextAlias: e[0],
|
|
259
|
+
aggregateName: e[1]
|
|
260
|
+
} : null;
|
|
261
|
+
}
|
|
262
|
+
function Ne(r) {
|
|
263
|
+
const e = r?.map((n) => Oe(n)).filter((n) => n !== null);
|
|
264
|
+
if (!e)
|
|
265
|
+
return /* @__PURE__ */ new Map();
|
|
266
|
+
const t = /* @__PURE__ */ new Map();
|
|
267
|
+
return e.forEach((n) => {
|
|
268
|
+
t.set(n.tag.name, {
|
|
269
|
+
aggregate: n,
|
|
270
|
+
commands: /* @__PURE__ */ new Map(),
|
|
271
|
+
events: /* @__PURE__ */ new Map()
|
|
272
|
+
});
|
|
273
|
+
}), t;
|
|
274
|
+
}
|
|
275
|
+
function De(r) {
|
|
276
|
+
if (!r)
|
|
277
|
+
return null;
|
|
278
|
+
const e = r.split(".");
|
|
279
|
+
return e.length != 3 ? null : e[2];
|
|
280
|
+
}
|
|
281
|
+
const be = "#/components/responses/wow.CommandOk", qe = "#/components/parameters/wow.id";
|
|
282
|
+
class Me {
|
|
283
283
|
/**
|
|
284
284
|
* Creates a new AggregateResolver instance.
|
|
285
285
|
* @param openAPI - The OpenAPI specification to resolve aggregates from
|
|
286
286
|
*/
|
|
287
287
|
constructor(e) {
|
|
288
|
-
this.openAPI = e, this.aggregates =
|
|
288
|
+
this.openAPI = e, this.aggregates = Ne(e.tags), this.build();
|
|
289
289
|
}
|
|
290
290
|
aggregates;
|
|
291
291
|
/**
|
|
@@ -294,7 +294,7 @@ class qe {
|
|
|
294
294
|
*/
|
|
295
295
|
build() {
|
|
296
296
|
for (const [e, t] of Object.entries(this.openAPI.paths)) {
|
|
297
|
-
const n =
|
|
297
|
+
const n = H(t);
|
|
298
298
|
for (const o of n)
|
|
299
299
|
this.commands(e, o), this.state(o.operation), this.events(o.operation), this.fields(o.operation);
|
|
300
300
|
}
|
|
@@ -323,14 +323,14 @@ class qe {
|
|
|
323
323
|
const n = t.operation;
|
|
324
324
|
if (n.operationId === "wow.command.send")
|
|
325
325
|
return;
|
|
326
|
-
const o =
|
|
326
|
+
const o = De(n.operationId);
|
|
327
327
|
if (!o)
|
|
328
328
|
return;
|
|
329
|
-
const s =
|
|
330
|
-
if (!s || !
|
|
329
|
+
const s = M(n);
|
|
330
|
+
if (!s || !g(s) || s.$ref !== be || !n.requestBody)
|
|
331
331
|
return;
|
|
332
|
-
const i = n.parameters ?? [], a = i.filter((m) =>
|
|
333
|
-
(m) => !
|
|
332
|
+
const i = n.parameters ?? [], a = i.filter((m) => g(m) && m.$ref === qe).at(0), c = i.filter(
|
|
333
|
+
(m) => !g(m) && m.in === "path"
|
|
334
334
|
);
|
|
335
335
|
if (a) {
|
|
336
336
|
const m = Q(
|
|
@@ -339,11 +339,11 @@ class qe {
|
|
|
339
339
|
);
|
|
340
340
|
c.push(m);
|
|
341
341
|
}
|
|
342
|
-
const
|
|
343
|
-
|
|
342
|
+
const p = n.requestBody.content[S.APPLICATION_JSON].schema, u = T(
|
|
343
|
+
p,
|
|
344
344
|
this.openAPI.components
|
|
345
345
|
);
|
|
346
|
-
|
|
346
|
+
u.schema.title = u.schema.title || n.summary, u.schema.description = u.schema.description || n.description;
|
|
347
347
|
const ie = {
|
|
348
348
|
name: o,
|
|
349
349
|
method: t.method,
|
|
@@ -351,12 +351,12 @@ class qe {
|
|
|
351
351
|
pathParameters: c,
|
|
352
352
|
summary: n.summary,
|
|
353
353
|
description: n.description,
|
|
354
|
-
schema:
|
|
354
|
+
schema: u,
|
|
355
355
|
operation: n
|
|
356
356
|
};
|
|
357
357
|
n.tags?.forEach((m) => {
|
|
358
|
-
const
|
|
359
|
-
|
|
358
|
+
const j = this.aggregates.get(m);
|
|
359
|
+
j && j.commands.set(o, ie);
|
|
360
360
|
});
|
|
361
361
|
}
|
|
362
362
|
/**
|
|
@@ -366,8 +366,8 @@ class qe {
|
|
|
366
366
|
state(e) {
|
|
367
367
|
if (!e.operationId?.endsWith(".snapshot_state.single"))
|
|
368
368
|
return;
|
|
369
|
-
const t =
|
|
370
|
-
if (!
|
|
369
|
+
const t = B(e);
|
|
370
|
+
if (!g(t))
|
|
371
371
|
return;
|
|
372
372
|
const n = T(
|
|
373
373
|
t,
|
|
@@ -385,24 +385,24 @@ class qe {
|
|
|
385
385
|
events(e) {
|
|
386
386
|
if (!this.openAPI.components || !e.operationId?.endsWith(".event.list_query"))
|
|
387
387
|
return;
|
|
388
|
-
const t =
|
|
389
|
-
if (
|
|
388
|
+
const t = B(e);
|
|
389
|
+
if (g(t))
|
|
390
390
|
return;
|
|
391
391
|
const n = t?.items;
|
|
392
|
-
if (!
|
|
392
|
+
if (!g(n))
|
|
393
393
|
return;
|
|
394
|
-
const s =
|
|
394
|
+
const s = E(
|
|
395
395
|
n,
|
|
396
396
|
this.openAPI.components
|
|
397
397
|
).properties.body.items.anyOf.map((i) => {
|
|
398
|
-
const a = i.title, c = i.properties.name.const,
|
|
399
|
-
|
|
398
|
+
const a = i.title, c = i.properties.name.const, l = i.properties.body, p = T(
|
|
399
|
+
l,
|
|
400
400
|
this.openAPI.components
|
|
401
401
|
);
|
|
402
|
-
return
|
|
402
|
+
return p.schema.title = p.schema.title || i.title, {
|
|
403
403
|
title: a,
|
|
404
404
|
name: c,
|
|
405
|
-
schema:
|
|
405
|
+
schema: p
|
|
406
406
|
};
|
|
407
407
|
});
|
|
408
408
|
e.tags?.forEach((i) => {
|
|
@@ -419,10 +419,10 @@ class qe {
|
|
|
419
419
|
fields(e) {
|
|
420
420
|
if (!this.openAPI.components || !e.operationId?.endsWith(".snapshot.count"))
|
|
421
421
|
return;
|
|
422
|
-
const n =
|
|
422
|
+
const n = L(
|
|
423
423
|
e.requestBody,
|
|
424
424
|
this.openAPI.components
|
|
425
|
-
).content[S.APPLICATION_JSON].schema, s =
|
|
425
|
+
).content[S.APPLICATION_JSON].schema, s = E(
|
|
426
426
|
n,
|
|
427
427
|
this.openAPI.components
|
|
428
428
|
).properties?.field, i = T(s, this.openAPI.components);
|
|
@@ -432,7 +432,7 @@ class qe {
|
|
|
432
432
|
});
|
|
433
433
|
}
|
|
434
434
|
}
|
|
435
|
-
const P = "@ahoo-wang/fetcher-wow",
|
|
435
|
+
const P = "@ahoo-wang/fetcher-wow", je = {
|
|
436
436
|
"wow.command.CommandResult": "CommandResult",
|
|
437
437
|
"wow.MessageHeaderSqlType": "MessageHeaderSqlType",
|
|
438
438
|
"wow.api.BindingError": "BindingError",
|
|
@@ -464,7 +464,7 @@ const P = "@ahoo-wang/fetcher-wow", Me = {
|
|
|
464
464
|
function d(r) {
|
|
465
465
|
if (!r)
|
|
466
466
|
return { name: "", path: "/" };
|
|
467
|
-
const e =
|
|
467
|
+
const e = je[r];
|
|
468
468
|
if (e)
|
|
469
469
|
return { name: e, path: P };
|
|
470
470
|
const t = r.split(".");
|
|
@@ -474,8 +474,6 @@ function d(r) {
|
|
|
474
474
|
n = c;
|
|
475
475
|
break;
|
|
476
476
|
}
|
|
477
|
-
if (n === -1)
|
|
478
|
-
return { name: r, path: "/" };
|
|
479
477
|
const o = t.slice(0, n), s = o.length > 0 ? `/${o.join("/")}` : "/", i = t.slice(n);
|
|
480
478
|
return { name: A(i), path: s };
|
|
481
479
|
}
|
|
@@ -483,12 +481,12 @@ function y(r) {
|
|
|
483
481
|
const e = $(r);
|
|
484
482
|
return d(e);
|
|
485
483
|
}
|
|
486
|
-
class
|
|
484
|
+
class Fe {
|
|
487
485
|
constructor(e) {
|
|
488
486
|
this.context = e;
|
|
489
487
|
}
|
|
490
488
|
getOrCreateSourceFile(e) {
|
|
491
|
-
const t =
|
|
489
|
+
const t = Ee(e);
|
|
492
490
|
return this.context.getOrCreateSourceFile(t);
|
|
493
491
|
}
|
|
494
492
|
/**
|
|
@@ -567,16 +565,16 @@ class je {
|
|
|
567
565
|
s && x(s, t.title, t.description);
|
|
568
566
|
}
|
|
569
567
|
process(e, t, n) {
|
|
570
|
-
if (
|
|
568
|
+
if (he(n))
|
|
571
569
|
return t.addEnum({
|
|
572
570
|
name: e.name,
|
|
573
571
|
isExported: !0,
|
|
574
572
|
members: n.enum.filter((s) => typeof s == "string" && s.length > 0).map((s) => ({
|
|
575
|
-
name:
|
|
573
|
+
name: ue(s),
|
|
576
574
|
initializer: `'${s}'`
|
|
577
575
|
}))
|
|
578
576
|
});
|
|
579
|
-
if (O(n) &&
|
|
577
|
+
if (O(n) && g(n.items)) {
|
|
580
578
|
const s = y(n.items);
|
|
581
579
|
return I(
|
|
582
580
|
e,
|
|
@@ -585,7 +583,7 @@ class je {
|
|
|
585
583
|
s
|
|
586
584
|
), t.addTypeAlias({
|
|
587
585
|
name: e.name,
|
|
588
|
-
type:
|
|
586
|
+
type: z(s.name),
|
|
589
587
|
isExported: !0
|
|
590
588
|
});
|
|
591
589
|
}
|
|
@@ -598,8 +596,8 @@ class je {
|
|
|
598
596
|
e,
|
|
599
597
|
n,
|
|
600
598
|
o
|
|
601
|
-
) : (
|
|
602
|
-
if (
|
|
599
|
+
) : (W(n) && (n.anyOf || n.oneOf || n.allOf).forEach((i) => {
|
|
600
|
+
if (g(i)) {
|
|
603
601
|
const a = y(i);
|
|
604
602
|
I(
|
|
605
603
|
e,
|
|
@@ -641,12 +639,12 @@ class je {
|
|
|
641
639
|
c ? c.setType(a) : c = o.addProperty({
|
|
642
640
|
name: s,
|
|
643
641
|
type: a
|
|
644
|
-
}),
|
|
642
|
+
}), g(i) || x(c, i.title, i.description);
|
|
645
643
|
}
|
|
646
644
|
return o;
|
|
647
645
|
}
|
|
648
646
|
resolvePropertyType(e, t, n, o) {
|
|
649
|
-
if (
|
|
647
|
+
if (g(o)) {
|
|
650
648
|
const s = y(o);
|
|
651
649
|
return I(
|
|
652
650
|
e,
|
|
@@ -664,11 +662,11 @@ class je {
|
|
|
664
662
|
n,
|
|
665
663
|
o.items
|
|
666
664
|
);
|
|
667
|
-
return
|
|
665
|
+
return z(s);
|
|
668
666
|
}
|
|
669
|
-
if (o.type &&
|
|
667
|
+
if (o.type && q(o.type))
|
|
670
668
|
return C(o.type);
|
|
671
|
-
if (
|
|
669
|
+
if (W(o))
|
|
672
670
|
return this.resolvePropertyCompositionType(
|
|
673
671
|
e,
|
|
674
672
|
t,
|
|
@@ -690,7 +688,7 @@ class je {
|
|
|
690
688
|
resolvePropertyCompositionType(e, t, n) {
|
|
691
689
|
const o = n.anyOf || n.oneOf || n.allOf, s = /* @__PURE__ */ new Set();
|
|
692
690
|
o.forEach((a) => {
|
|
693
|
-
if (
|
|
691
|
+
if (g(a)) {
|
|
694
692
|
const c = y(a);
|
|
695
693
|
I(
|
|
696
694
|
e,
|
|
@@ -702,191 +700,448 @@ class je {
|
|
|
702
700
|
}
|
|
703
701
|
s.add(C(a.type ?? "string"));
|
|
704
702
|
});
|
|
705
|
-
const i =
|
|
703
|
+
const i = ye(n) ? "|" : "&";
|
|
706
704
|
return Array.from(s).join(i);
|
|
707
705
|
}
|
|
708
706
|
}
|
|
709
|
-
|
|
707
|
+
const Ge = "@ahoo-wang/fetcher-decorator", _e = [
|
|
708
|
+
"type ApiMetadata",
|
|
709
|
+
"type ApiMetadataCapable",
|
|
710
|
+
"api",
|
|
711
|
+
"post",
|
|
712
|
+
"put",
|
|
713
|
+
"patch",
|
|
714
|
+
"del",
|
|
715
|
+
"request",
|
|
716
|
+
"attribute",
|
|
717
|
+
"path",
|
|
718
|
+
"autoGeneratedError"
|
|
719
|
+
], We = {
|
|
720
|
+
type: "Promise<Response>",
|
|
721
|
+
metadata: "{resultExtractor: ResultExtractors.Response }"
|
|
722
|
+
}, N = `{
|
|
723
|
+
headers: { Accept: ContentTypeValues.TEXT_EVENT_STREAM },
|
|
724
|
+
resultExtractor: JsonEventStreamResultExtractor,
|
|
725
|
+
}`;
|
|
726
|
+
function ne(r) {
|
|
727
|
+
R(r, Ge, _e);
|
|
728
|
+
}
|
|
729
|
+
function oe(r, e, t = []) {
|
|
730
|
+
return e.addClass({
|
|
731
|
+
name: r,
|
|
732
|
+
isExported: !0,
|
|
733
|
+
decorators: [
|
|
734
|
+
{
|
|
735
|
+
name: "api",
|
|
736
|
+
arguments: t
|
|
737
|
+
}
|
|
738
|
+
]
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
function re(r, e) {
|
|
742
|
+
r.addImplements("ApiMetadataCapable"), r.addConstructor({
|
|
743
|
+
parameters: [
|
|
744
|
+
{
|
|
745
|
+
name: "apiMetadata",
|
|
746
|
+
type: "ApiMetadata",
|
|
747
|
+
hasQuestionToken: e === void 0,
|
|
748
|
+
scope: ae.Public,
|
|
749
|
+
isReadonly: !0,
|
|
750
|
+
initializer: e
|
|
751
|
+
}
|
|
752
|
+
]
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
function ze(r) {
|
|
710
756
|
let e = 0, t = 0;
|
|
711
757
|
return r.commands.forEach((n) => {
|
|
712
|
-
n.path.startsWith(
|
|
758
|
+
n.path.startsWith(F.TENANT) && (e += 1), n.path.startsWith(F.OWNER) && (t += 1);
|
|
713
759
|
}), e === 0 && t === 0 ? "ResourceAttributionPathSpec.NONE" : e > t ? "ResourceAttributionPathSpec.TENANT" : "ResourceAttributionPathSpec.OWNER";
|
|
714
760
|
}
|
|
715
|
-
function
|
|
761
|
+
function se(r, e, t, n) {
|
|
716
762
|
const o = `${t.contextAlias}/${t.aggregateName}/${n}.ts`;
|
|
717
|
-
return
|
|
763
|
+
return te(r, e, o);
|
|
718
764
|
}
|
|
719
|
-
function
|
|
765
|
+
function Be(r, e) {
|
|
720
766
|
return `${A(r.aggregateName)}${e}`;
|
|
721
767
|
}
|
|
722
|
-
function
|
|
768
|
+
function D(r) {
|
|
723
769
|
return r === "delete" ? "del" : r;
|
|
724
770
|
}
|
|
725
|
-
class
|
|
771
|
+
class ke {
|
|
726
772
|
/**
|
|
727
|
-
* Creates a new
|
|
728
|
-
* @param context - The generation context containing OpenAPI spec and
|
|
773
|
+
* Creates a new ApiClientGenerator instance.
|
|
774
|
+
* @param context - The generation context containing OpenAPI spec and configuration
|
|
729
775
|
*/
|
|
730
776
|
constructor(e) {
|
|
731
|
-
this.context = e;
|
|
777
|
+
this.context = e, this.apiMetadataCtorInitializer = this.context.currentContextAlias ? `{basePath:'${this.context.currentContextAlias}'}` : void 0;
|
|
732
778
|
}
|
|
779
|
+
defaultParameterRequestType = "ParameterRequest";
|
|
780
|
+
defaultReturnType = We;
|
|
781
|
+
apiMetadataCtorInitializer;
|
|
733
782
|
/**
|
|
734
|
-
* Generates
|
|
783
|
+
* Generates API client classes for all valid tags in the OpenAPI specification.
|
|
784
|
+
* Processes tags, groups operations, and creates client classes with methods.
|
|
735
785
|
*/
|
|
736
786
|
generate() {
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
this.context.logger.info("--- Generating Query Clients ---"), this.context.logger.progress(
|
|
742
|
-
`Generating query clients for ${e} aggregates`
|
|
787
|
+
this.context.logger.info("Starting API client generation");
|
|
788
|
+
const e = this.resolveApiTags();
|
|
789
|
+
this.context.logger.info(
|
|
790
|
+
`Resolved ${e.size} API client tags: ${Array.from(e.keys()).join(", ")}`
|
|
743
791
|
);
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
t,
|
|
749
|
-
e,
|
|
750
|
-
`Processing query client for aggregate: ${o.aggregate.aggregateName}`
|
|
751
|
-
), this.processQueryClient(o);
|
|
752
|
-
});
|
|
753
|
-
this.context.logger.success("Query client generation completed");
|
|
792
|
+
const t = this.groupOperations(e);
|
|
793
|
+
this.context.logger.info(
|
|
794
|
+
`Grouped operations into ${t.size} tag groups`
|
|
795
|
+
), this.generateApiClients(e, t), this.context.logger.success("API client generation completed");
|
|
754
796
|
}
|
|
755
797
|
/**
|
|
756
|
-
*
|
|
757
|
-
* @param
|
|
758
|
-
* @param
|
|
759
|
-
* @returns The source file for the client
|
|
798
|
+
* Generates API client classes for each tag group.
|
|
799
|
+
* @param apiClientTags - Map of valid API client tags
|
|
800
|
+
* @param groupOperations - Map of operations grouped by tag
|
|
760
801
|
*/
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
this.context.outputDir,
|
|
765
|
-
e,
|
|
766
|
-
t
|
|
802
|
+
generateApiClients(e, t) {
|
|
803
|
+
this.context.logger.info(
|
|
804
|
+
`Generating ${t.size} API client classes`
|
|
767
805
|
);
|
|
806
|
+
let n = 0;
|
|
807
|
+
for (const [o, s] of t) {
|
|
808
|
+
n++, this.context.logger.progressWithCount(
|
|
809
|
+
n,
|
|
810
|
+
t.size,
|
|
811
|
+
`Generating API client for tag: ${o}`
|
|
812
|
+
);
|
|
813
|
+
const i = e.get(o);
|
|
814
|
+
this.generateApiClient(i, s);
|
|
815
|
+
}
|
|
768
816
|
}
|
|
769
817
|
/**
|
|
770
|
-
*
|
|
771
|
-
* @param
|
|
818
|
+
* Creates a new source file for the API client.
|
|
819
|
+
* @param modelInfo - The model information for the client
|
|
820
|
+
* @returns The created source file
|
|
772
821
|
*/
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
822
|
+
createApiClientFile(e) {
|
|
823
|
+
let t = e.path;
|
|
824
|
+
return this.context.currentContextAlias && (t = w(this.context.currentContextAlias, t)), t = w(t, `${e.name}ApiClient.ts`), this.context.logger.info(`Creating API client file: ${t}`), this.context.getOrCreateSourceFile(t);
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Generates a single API client class for the given tag and operations.
|
|
828
|
+
* @param tag - The OpenAPI tag for the client
|
|
829
|
+
* @param operations - Set of operations for this client
|
|
830
|
+
*/
|
|
831
|
+
generateApiClient(e, t) {
|
|
832
|
+
const n = d(e.name);
|
|
833
|
+
this.context.logger.info(
|
|
834
|
+
`Generating API client class: ${n.name}ApiClient with ${t.size} operations`
|
|
835
|
+
);
|
|
836
|
+
const o = this.createApiClientFile(n);
|
|
837
|
+
ne(o);
|
|
838
|
+
const s = oe(
|
|
839
|
+
n.name + "ApiClient",
|
|
840
|
+
o
|
|
777
841
|
);
|
|
842
|
+
x(s, e.description), re(s, this.apiMetadataCtorInitializer), this.context.logger.info(
|
|
843
|
+
`Processing ${t.size} operations for ${n.name}ApiClient`
|
|
844
|
+
), t.forEach((i) => {
|
|
845
|
+
this.processOperation(e, o, s, i);
|
|
846
|
+
}), this.context.logger.success(
|
|
847
|
+
`Completed API client: ${n.name}ApiClient`
|
|
848
|
+
);
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Generates a unique method name for the operation.
|
|
852
|
+
* @param apiClientClass - The client class to check for existing methods
|
|
853
|
+
* @param operation - The operation to generate a name for
|
|
854
|
+
* @returns A unique camelCase method name
|
|
855
|
+
*/
|
|
856
|
+
getMethodName(e, t) {
|
|
857
|
+
const n = t.operationId.split(".");
|
|
858
|
+
for (let o = n.length - 1; o >= 0; o--) {
|
|
859
|
+
const s = h(n.slice(o));
|
|
860
|
+
if (!e.getMethod(s))
|
|
861
|
+
return s;
|
|
862
|
+
}
|
|
863
|
+
return h(n);
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* Resolves the request type for an operation based on its request body.
|
|
867
|
+
* @param sourceFile - The source file to add imports to
|
|
868
|
+
* @param operation - The operation to resolve the request type for
|
|
869
|
+
* @returns The resolved request type string
|
|
870
|
+
*/
|
|
871
|
+
resolveRequestType(e, t) {
|
|
872
|
+
if (!t.requestBody)
|
|
873
|
+
return this.context.logger.info(
|
|
874
|
+
`No request body found for operation ${t.operationId}, using default: ${this.defaultParameterRequestType}`
|
|
875
|
+
), this.defaultParameterRequestType;
|
|
876
|
+
let n;
|
|
877
|
+
if (g(t.requestBody) ? (this.context.logger.info(
|
|
878
|
+
`Extracting request body from reference for operation: ${t.operationId}`
|
|
879
|
+
), n = L(
|
|
880
|
+
t.requestBody,
|
|
881
|
+
this.context.openAPI.components
|
|
882
|
+
)) : n = t.requestBody, !n)
|
|
883
|
+
return this.context.logger.info(
|
|
884
|
+
`Request body extraction failed for operation ${t.operationId}, using default: ${this.defaultParameterRequestType}`
|
|
885
|
+
), this.defaultParameterRequestType;
|
|
886
|
+
if (n.content["multipart/form-data"])
|
|
887
|
+
return this.context.logger.info(
|
|
888
|
+
`Detected multipart/form-data content for operation ${t.operationId}, using ParameterRequest<FormData>`
|
|
889
|
+
), "ParameterRequest<FormData>";
|
|
890
|
+
if (n.content["application/json"]) {
|
|
891
|
+
const o = n.content["application/json"].schema;
|
|
892
|
+
if (g(o)) {
|
|
893
|
+
const s = y(o);
|
|
894
|
+
this.context.logger.info(
|
|
895
|
+
`Adding import for request body model: ${s.name} from ${s.path}`
|
|
896
|
+
), f(e, this.context.outputDir, s);
|
|
897
|
+
const i = `ParameterRequest<${s.name}>`;
|
|
898
|
+
return this.context.logger.info(
|
|
899
|
+
`Resolved request type for operation ${t.operationId}: ${i}`
|
|
900
|
+
), i;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
return this.context.logger.info(
|
|
904
|
+
`Using default request type for operation ${t.operationId}: ${this.defaultParameterRequestType}`
|
|
905
|
+
), this.defaultParameterRequestType;
|
|
906
|
+
}
|
|
907
|
+
/**
|
|
908
|
+
* Resolves method parameters for an operation.
|
|
909
|
+
* @param tag - The tag for parameter filtering
|
|
910
|
+
* @param sourceFile - The source file to add imports to
|
|
911
|
+
* @param operation - The operation to resolve parameters for
|
|
912
|
+
* @returns Array of parameter declarations
|
|
913
|
+
*/
|
|
914
|
+
resolveParameters(e, t, n) {
|
|
915
|
+
const o = Ce(n, this.context.openAPI.components).filter((a) => !this.context.isIgnoreApiClientPathParameters(
|
|
916
|
+
e.name,
|
|
917
|
+
a.name
|
|
918
|
+
));
|
|
778
919
|
this.context.logger.info(
|
|
779
|
-
`
|
|
780
|
-
)
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
920
|
+
`Found ${o.length} path parameters for operation ${n.operationId}`
|
|
921
|
+
);
|
|
922
|
+
const s = o.map((a) => {
|
|
923
|
+
const c = Y(a);
|
|
924
|
+
return this.context.logger.info(
|
|
925
|
+
`Adding path parameter: ${a.name} (type: ${c})`
|
|
926
|
+
), {
|
|
927
|
+
name: a.name,
|
|
928
|
+
type: c,
|
|
929
|
+
hasQuestionToken: !1,
|
|
930
|
+
decorators: [
|
|
931
|
+
{
|
|
932
|
+
name: "path",
|
|
933
|
+
arguments: [`'${a.name}'`]
|
|
934
|
+
}
|
|
935
|
+
]
|
|
936
|
+
};
|
|
937
|
+
}), i = this.resolveRequestType(t, n);
|
|
938
|
+
return this.context.logger.info(`Adding httpRequest parameter: ${i}`), s.push({
|
|
939
|
+
name: "httpRequest",
|
|
940
|
+
hasQuestionToken: i === this.defaultParameterRequestType,
|
|
941
|
+
type: `${i}`,
|
|
942
|
+
decorators: [
|
|
943
|
+
{
|
|
944
|
+
name: "request",
|
|
945
|
+
arguments: []
|
|
946
|
+
}
|
|
788
947
|
]
|
|
789
|
-
})
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
948
|
+
}), this.context.logger.info(
|
|
949
|
+
"Adding attributes parameter: Record<string, any>"
|
|
950
|
+
), s.push({
|
|
951
|
+
name: "attributes",
|
|
952
|
+
hasQuestionToken: !0,
|
|
953
|
+
type: "Record<string, any>",
|
|
954
|
+
decorators: [
|
|
796
955
|
{
|
|
797
|
-
name:
|
|
798
|
-
|
|
799
|
-
initializer: `{
|
|
800
|
-
contextAlias: '${e.aggregate.contextAlias}',
|
|
801
|
-
aggregateName: '${e.aggregate.aggregateName}',
|
|
802
|
-
resourceAttribution: ${Ge(e)},
|
|
803
|
-
}`
|
|
956
|
+
name: "attribute",
|
|
957
|
+
arguments: []
|
|
804
958
|
}
|
|
805
|
-
]
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
959
|
+
]
|
|
960
|
+
}), s;
|
|
961
|
+
}
|
|
962
|
+
/**
|
|
963
|
+
* Resolves the return type for a schema.
|
|
964
|
+
* @param sourceFile - The source file to add imports to
|
|
965
|
+
* @param schema - The schema to resolve the return type for
|
|
966
|
+
* @returns The resolved return type string
|
|
967
|
+
*/
|
|
968
|
+
resolveSchemaReturnType(e, t) {
|
|
969
|
+
const n = "Promise<any>";
|
|
970
|
+
if (g(t)) {
|
|
971
|
+
const o = y(t);
|
|
814
972
|
this.context.logger.info(
|
|
815
|
-
`Adding import for
|
|
816
|
-
), f(
|
|
973
|
+
`Adding import for response model: ${o.name} from ${o.path}`
|
|
974
|
+
), f(e, this.context.outputDir, o);
|
|
975
|
+
const s = `Promise<${o.name}>`;
|
|
976
|
+
return this.context.logger.info(`Resolved reference return type: ${s}`), s;
|
|
817
977
|
}
|
|
818
|
-
|
|
978
|
+
if (!t.type)
|
|
979
|
+
return this.context.logger.info(
|
|
980
|
+
`Schema has no type, using default return type: ${n}`
|
|
981
|
+
), n;
|
|
982
|
+
if (q(t.type)) {
|
|
983
|
+
const s = `Promise<${C(t.type)}>`;
|
|
984
|
+
return this.context.logger.info(`Resolved primitive return type: ${s}`), s;
|
|
985
|
+
}
|
|
986
|
+
return this.context.logger.info(
|
|
987
|
+
`Using default return type: ${n}`
|
|
988
|
+
), n;
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* Resolves the return type for an operation based on its responses.
|
|
992
|
+
* @param sourceFile - The source file to add imports to
|
|
993
|
+
* @param operation - The operation to resolve the return type for
|
|
994
|
+
* @returns Object containing type and optional stream flag
|
|
995
|
+
*/
|
|
996
|
+
resolveReturnType(e, t) {
|
|
997
|
+
const n = M(t);
|
|
998
|
+
if (!n)
|
|
999
|
+
return this.context.logger.info(
|
|
1000
|
+
`No OK response found for operation ${t.operationId}, using default return type: ${this.defaultReturnType.type}`
|
|
1001
|
+
), this.defaultReturnType;
|
|
1002
|
+
const o = J(n) || de(n);
|
|
1003
|
+
if (o) {
|
|
1004
|
+
const i = this.resolveSchemaReturnType(e, o);
|
|
1005
|
+
return this.context.logger.info(
|
|
1006
|
+
`Resolved JSON/wildcard response return type for operation ${t.operationId}: ${i}`
|
|
1007
|
+
), {
|
|
1008
|
+
type: i
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
const s = me(n);
|
|
1012
|
+
if (s) {
|
|
1013
|
+
if (g(s)) {
|
|
1014
|
+
const a = E(
|
|
1015
|
+
s,
|
|
1016
|
+
this.context.openAPI.components
|
|
1017
|
+
);
|
|
1018
|
+
if (O(a) && g(a.items)) {
|
|
1019
|
+
const c = y(a.items);
|
|
1020
|
+
this.context.logger.info(
|
|
1021
|
+
`Adding import for event stream model: ${c.name} from ${c.path}`
|
|
1022
|
+
), f(e, this.context.outputDir, c);
|
|
1023
|
+
const p = `Promise<JsonServerSentEventStream<${c.name.includes("ServerSentEvent") ? `${c.name}['data']` : c.name}>>`;
|
|
1024
|
+
return this.context.logger.info(
|
|
1025
|
+
`Resolved event stream return type for operation ${t.operationId}: ${p}`
|
|
1026
|
+
), {
|
|
1027
|
+
type: p,
|
|
1028
|
+
metadata: N
|
|
1029
|
+
};
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
const i = "Promise<JsonServerSentEventStream<any>>";
|
|
1033
|
+
return this.context.logger.info(
|
|
1034
|
+
`Resolved generic event stream return type for operation ${t.operationId}: ${i}`
|
|
1035
|
+
), { type: i, metadata: N };
|
|
1036
|
+
}
|
|
1037
|
+
return this.context.logger.info(
|
|
1038
|
+
`Using default return type for operation ${t.operationId}: ${this.defaultReturnType.type}`
|
|
1039
|
+
), this.defaultReturnType;
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* Processes a single operation and adds it as a method to the client class.
|
|
1043
|
+
* @param tag - The tag for parameter filtering
|
|
1044
|
+
* @param sourceFile - The source file containing the client
|
|
1045
|
+
* @param apiClientClass - The client class to add the method to
|
|
1046
|
+
* @param operation - The operation to process
|
|
1047
|
+
*/
|
|
1048
|
+
processOperation(e, t, n, o) {
|
|
819
1049
|
this.context.logger.info(
|
|
820
|
-
`
|
|
821
|
-
)
|
|
1050
|
+
`Processing operation: ${o.operation.operationId} (${o.method} ${o.path})`
|
|
1051
|
+
);
|
|
1052
|
+
const s = this.getMethodName(n, o.operation);
|
|
1053
|
+
this.context.logger.info(`Generated method name: ${s}`);
|
|
1054
|
+
const i = this.resolveParameters(
|
|
1055
|
+
e,
|
|
1056
|
+
t,
|
|
1057
|
+
o.operation
|
|
1058
|
+
), a = this.resolveReturnType(t, o.operation), c = a.metadata ? {
|
|
1059
|
+
name: D(o.method),
|
|
1060
|
+
arguments: [`'${o.path}'`, a.metadata]
|
|
1061
|
+
} : {
|
|
1062
|
+
name: D(o.method),
|
|
1063
|
+
arguments: [`'${o.path}'`]
|
|
1064
|
+
};
|
|
1065
|
+
this.context.logger.info(
|
|
1066
|
+
`Creating method with ${i.length} parameters, return type: ${a.type}`
|
|
1067
|
+
);
|
|
1068
|
+
const l = n.addMethod({
|
|
822
1069
|
name: s,
|
|
823
|
-
|
|
1070
|
+
decorators: [c],
|
|
1071
|
+
parameters: i,
|
|
1072
|
+
returnType: a.type,
|
|
1073
|
+
statements: [
|
|
1074
|
+
`throw autoGeneratedError(${i.map((p) => p.name).join(",")});`
|
|
1075
|
+
]
|
|
824
1076
|
});
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
1077
|
+
x(
|
|
1078
|
+
l,
|
|
1079
|
+
o.operation.summary,
|
|
1080
|
+
o.operation.description
|
|
1081
|
+
), this.context.logger.success(`Operation method generated: ${s}`);
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* Groups operations by their tags for client generation.
|
|
1085
|
+
* @param apiClientTags - Map of valid API client tags
|
|
1086
|
+
* @returns Map of operations grouped by tag name
|
|
1087
|
+
*/
|
|
1088
|
+
groupOperations(e) {
|
|
1089
|
+
this.context.logger.info("Grouping operations by API client tags");
|
|
1090
|
+
const t = /* @__PURE__ */ new Map();
|
|
1091
|
+
let n = 0;
|
|
1092
|
+
for (const [o, s] of Object.entries(this.context.openAPI.paths)) {
|
|
1093
|
+
const i = H(s).filter(
|
|
1094
|
+
(a) => {
|
|
1095
|
+
if (!a.operation.operationId)
|
|
1096
|
+
return !1;
|
|
1097
|
+
const c = a.operation.tags;
|
|
1098
|
+
return !c || c.length == 0 ? !1 : c.every((l) => e.has(l));
|
|
836
1099
|
}
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
1100
|
+
);
|
|
1101
|
+
this.context.logger.info(
|
|
1102
|
+
`Path ${o}: found ${i.length} valid operations`
|
|
1103
|
+
);
|
|
1104
|
+
for (const a of i)
|
|
1105
|
+
a.operation.tags.forEach((c) => {
|
|
1106
|
+
const l = {
|
|
1107
|
+
...a,
|
|
1108
|
+
path: o
|
|
1109
|
+
};
|
|
1110
|
+
t.has(c) || t.set(c, /* @__PURE__ */ new Set()), t.get(c).add(l), n++;
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
return this.context.logger.info(
|
|
1114
|
+
`Grouped ${n} operations into ${t.size} tag groups`
|
|
1115
|
+
), t;
|
|
1116
|
+
}
|
|
1117
|
+
/**
|
|
1118
|
+
* Resolves valid API client tags from the OpenAPI specification.
|
|
1119
|
+
* Filters out system tags like 'wow' and 'Actuator' and aggregate tags.
|
|
1120
|
+
* @returns Map of valid API client tags
|
|
1121
|
+
*/
|
|
1122
|
+
resolveApiTags() {
|
|
1123
|
+
this.context.logger.info(
|
|
1124
|
+
"Resolving API client tags from OpenAPI specification"
|
|
841
1125
|
);
|
|
1126
|
+
const e = /* @__PURE__ */ new Map(), t = this.context.openAPI.tags?.length || 0;
|
|
1127
|
+
let n = 0;
|
|
1128
|
+
return this.context.openAPI.tags?.forEach((o) => {
|
|
1129
|
+
o.name != "wow" && o.name != "Actuator" && !this.isAggregateTag(o) ? (e.set(o.name, o), n++, this.context.logger.info(`Included API client tag: ${o.name}`)) : this.context.logger.info(
|
|
1130
|
+
`Excluded tag: ${o.name} (wow/Actuator/aggregate)`
|
|
1131
|
+
);
|
|
1132
|
+
}), this.context.logger.info(
|
|
1133
|
+
`Resolved ${n} API client tags from ${t} total tags`
|
|
1134
|
+
), e;
|
|
1135
|
+
}
|
|
1136
|
+
isAggregateTag(e) {
|
|
1137
|
+
for (const t of this.context.contextAggregates.values())
|
|
1138
|
+
for (const n of t)
|
|
1139
|
+
if (n.aggregate.tag.name === e.name)
|
|
1140
|
+
return !0;
|
|
1141
|
+
return !1;
|
|
842
1142
|
}
|
|
843
1143
|
}
|
|
844
|
-
|
|
845
|
-
"type ApiMetadata",
|
|
846
|
-
"type ApiMetadataCapable",
|
|
847
|
-
"api",
|
|
848
|
-
"post",
|
|
849
|
-
"put",
|
|
850
|
-
"patch",
|
|
851
|
-
"del",
|
|
852
|
-
"request",
|
|
853
|
-
"attribute",
|
|
854
|
-
"path",
|
|
855
|
-
"autoGeneratedError"
|
|
856
|
-
], ne = `{
|
|
857
|
-
headers: { Accept: ContentTypeValues.TEXT_EVENT_STREAM },
|
|
858
|
-
resultExtractor: JsonEventStreamResultExtractor,
|
|
859
|
-
}`;
|
|
860
|
-
function oe(r) {
|
|
861
|
-
E(r, We, ze);
|
|
862
|
-
}
|
|
863
|
-
function re(r, e, t = []) {
|
|
864
|
-
return e.addClass({
|
|
865
|
-
name: r,
|
|
866
|
-
isExported: !0,
|
|
867
|
-
decorators: [
|
|
868
|
-
{
|
|
869
|
-
name: "api",
|
|
870
|
-
arguments: t
|
|
871
|
-
}
|
|
872
|
-
]
|
|
873
|
-
});
|
|
874
|
-
}
|
|
875
|
-
function se(r, e) {
|
|
876
|
-
r.addImplements("ApiMetadataCapable"), r.addConstructor({
|
|
877
|
-
parameters: [
|
|
878
|
-
{
|
|
879
|
-
name: "apiMetadata",
|
|
880
|
-
type: "ApiMetadata",
|
|
881
|
-
hasQuestionToken: e === void 0,
|
|
882
|
-
scope: ae.Public,
|
|
883
|
-
isReadonly: !0,
|
|
884
|
-
initializer: e
|
|
885
|
-
}
|
|
886
|
-
]
|
|
887
|
-
});
|
|
888
|
-
}
|
|
889
|
-
class Be {
|
|
1144
|
+
class Le {
|
|
890
1145
|
/**
|
|
891
1146
|
* Creates a new CommandClientGenerator instance.
|
|
892
1147
|
* @param context - The generation context containing OpenAPI spec and project details
|
|
@@ -926,7 +1181,7 @@ class Be {
|
|
|
926
1181
|
this.context.logger.info(
|
|
927
1182
|
`Processing command client for aggregate: ${e.aggregate.aggregateName} in context: ${e.aggregate.contextAlias}`
|
|
928
1183
|
);
|
|
929
|
-
const t =
|
|
1184
|
+
const t = se(
|
|
930
1185
|
this.context.project,
|
|
931
1186
|
this.context.outputDir,
|
|
932
1187
|
e.aggregate,
|
|
@@ -967,9 +1222,9 @@ class Be {
|
|
|
967
1222
|
namedImports: ["JsonEventStreamResultExtractor"]
|
|
968
1223
|
}), this.context.logger.info(
|
|
969
1224
|
"Adding import from @ahoo-wang/fetcher: ContentTypeValues"
|
|
970
|
-
),
|
|
1225
|
+
), R(t, "@ahoo-wang/fetcher", ["ContentTypeValues"]), this.context.logger.info(
|
|
971
1226
|
"Adding imports from @ahoo-wang/fetcher-decorator: ApiMetadata types and decorators"
|
|
972
|
-
),
|
|
1227
|
+
), ne(t), this.context.logger.info("Generating standard command client class"), this.processCommandClient(t, e), this.context.logger.info("Generating stream command client class"), this.processCommandClient(t, e, !0), this.context.logger.success(
|
|
973
1228
|
`Command client generation completed for aggregate: ${e.aggregate.aggregateName}`
|
|
974
1229
|
);
|
|
975
1230
|
}
|
|
@@ -998,14 +1253,14 @@ class Be {
|
|
|
998
1253
|
let o = "CommandClient", s = [], i = "Promise<CommandResult>";
|
|
999
1254
|
n && (o = "Stream" + o, s = [
|
|
1000
1255
|
"''",
|
|
1001
|
-
|
|
1256
|
+
N
|
|
1002
1257
|
], i = "Promise<CommandResultEventStream>");
|
|
1003
|
-
const a =
|
|
1258
|
+
const a = Be(
|
|
1004
1259
|
t.aggregate,
|
|
1005
1260
|
o
|
|
1006
|
-
), c =
|
|
1007
|
-
|
|
1008
|
-
this.processCommandMethod(t, e, c,
|
|
1261
|
+
), c = oe(a, e, s);
|
|
1262
|
+
re(c, this.defaultCommandClientOptionsName), t.commands.forEach((l) => {
|
|
1263
|
+
this.processCommandMethod(t, e, c, l, i);
|
|
1009
1264
|
});
|
|
1010
1265
|
}
|
|
1011
1266
|
resolveParameters(e, t, n) {
|
|
@@ -1017,245 +1272,27 @@ class Be {
|
|
|
1017
1272
|
e.name,
|
|
1018
1273
|
i.name
|
|
1019
1274
|
)).map((i) => {
|
|
1020
|
-
const a =
|
|
1275
|
+
const a = Y(i);
|
|
1021
1276
|
return this.context.logger.info(
|
|
1022
1277
|
`Adding path parameter: ${i.name} (type: ${a})`
|
|
1023
1278
|
), {
|
|
1024
1279
|
name: i.name,
|
|
1025
|
-
type: a,
|
|
1026
|
-
hasQuestionToken: !1,
|
|
1027
|
-
decorators: [
|
|
1028
|
-
{
|
|
1029
|
-
name: "path",
|
|
1030
|
-
arguments: [`'${i.name}'`]
|
|
1031
|
-
}
|
|
1032
|
-
]
|
|
1033
|
-
};
|
|
1034
|
-
});
|
|
1035
|
-
return this.context.logger.info(
|
|
1036
|
-
`Adding command request parameter: commandRequest (type: CommandRequest<${o.name}>)`
|
|
1037
|
-
), s.push({
|
|
1038
|
-
name: "commandRequest",
|
|
1039
|
-
hasQuestionToken: we(n.schema.schema),
|
|
1040
|
-
type: `CommandRequest<${o.name}>`,
|
|
1041
|
-
decorators: [
|
|
1042
|
-
{
|
|
1043
|
-
name: "request",
|
|
1044
|
-
arguments: []
|
|
1045
|
-
}
|
|
1046
|
-
]
|
|
1047
|
-
}), this.context.logger.info(
|
|
1048
|
-
"Adding attributes parameter: attributes (type: Record<string, any>)"
|
|
1049
|
-
), s.push({
|
|
1050
|
-
name: "attributes",
|
|
1051
|
-
hasQuestionToken: !0,
|
|
1052
|
-
type: "Record<string, any>",
|
|
1053
|
-
decorators: [
|
|
1054
|
-
{
|
|
1055
|
-
name: "attribute",
|
|
1056
|
-
arguments: []
|
|
1057
|
-
}
|
|
1058
|
-
]
|
|
1059
|
-
}), s;
|
|
1060
|
-
}
|
|
1061
|
-
processCommandMethod(e, t, n, o, s) {
|
|
1062
|
-
this.context.logger.info(
|
|
1063
|
-
`Generating command method: ${h(o.name)} for command: ${o.name}`
|
|
1064
|
-
), this.context.logger.info(
|
|
1065
|
-
`Command method details: HTTP ${o.method}, path: ${o.path}, return type: ${s}`
|
|
1066
|
-
);
|
|
1067
|
-
const i = this.resolveParameters(e.aggregate.tag, t, o), a = n.addMethod({
|
|
1068
|
-
name: h(o.name),
|
|
1069
|
-
decorators: [
|
|
1070
|
-
{
|
|
1071
|
-
name: N(o.method),
|
|
1072
|
-
arguments: [`${this.getEndpointPath(o)}`]
|
|
1073
|
-
}
|
|
1074
|
-
],
|
|
1075
|
-
parameters: i,
|
|
1076
|
-
returnType: s,
|
|
1077
|
-
statements: [
|
|
1078
|
-
`throw autoGeneratedError(${i.map((c) => c.name).join(",")});`
|
|
1079
|
-
]
|
|
1080
|
-
});
|
|
1081
|
-
(o.summary || o.description) && this.context.logger.info(
|
|
1082
|
-
`Adding JSDoc documentation for method: ${h(o.name)}`
|
|
1083
|
-
), x(a, o.summary, o.description), this.context.logger.success(
|
|
1084
|
-
`Command method generated: ${h(o.name)}`
|
|
1085
|
-
);
|
|
1086
|
-
}
|
|
1087
|
-
}
|
|
1088
|
-
class ke {
|
|
1089
|
-
/**
|
|
1090
|
-
* Creates a new ApiClientGenerator instance.
|
|
1091
|
-
* @param context - The generation context containing OpenAPI spec and configuration
|
|
1092
|
-
*/
|
|
1093
|
-
constructor(e) {
|
|
1094
|
-
this.context = e, this.apiMetadataCtorInitializer = this.context.currentContextAlias ? `{basePath:'${this.context.currentContextAlias}'}` : void 0;
|
|
1095
|
-
}
|
|
1096
|
-
defaultParameterRequestType = "ParameterRequest";
|
|
1097
|
-
defaultReturnType = { type: "Promise<any>" };
|
|
1098
|
-
apiMetadataCtorInitializer;
|
|
1099
|
-
/**
|
|
1100
|
-
* Generates API client classes for all valid tags in the OpenAPI specification.
|
|
1101
|
-
* Processes tags, groups operations, and creates client classes with methods.
|
|
1102
|
-
*/
|
|
1103
|
-
generate() {
|
|
1104
|
-
this.context.logger.info("Starting API client generation");
|
|
1105
|
-
const e = this.resolveApiTags();
|
|
1106
|
-
this.context.logger.info(
|
|
1107
|
-
`Resolved ${e.size} API client tags: ${Array.from(e.keys()).join(", ")}`
|
|
1108
|
-
);
|
|
1109
|
-
const t = this.groupOperations(e);
|
|
1110
|
-
this.context.logger.info(
|
|
1111
|
-
`Grouped operations into ${t.size} tag groups`
|
|
1112
|
-
), this.generateApiClients(e, t), this.context.logger.success("API client generation completed");
|
|
1113
|
-
}
|
|
1114
|
-
/**
|
|
1115
|
-
* Generates API client classes for each tag group.
|
|
1116
|
-
* @param apiClientTags - Map of valid API client tags
|
|
1117
|
-
* @param groupOperations - Map of operations grouped by tag
|
|
1118
|
-
*/
|
|
1119
|
-
generateApiClients(e, t) {
|
|
1120
|
-
this.context.logger.info(
|
|
1121
|
-
`Generating ${t.size} API client classes`
|
|
1122
|
-
);
|
|
1123
|
-
let n = 0;
|
|
1124
|
-
for (const [o, s] of t) {
|
|
1125
|
-
n++, this.context.logger.progressWithCount(
|
|
1126
|
-
n,
|
|
1127
|
-
t.size,
|
|
1128
|
-
`Generating API client for tag: ${o}`
|
|
1129
|
-
);
|
|
1130
|
-
const i = e.get(o);
|
|
1131
|
-
this.generateApiClient(i, s);
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
/**
|
|
1135
|
-
* Creates a new source file for the API client.
|
|
1136
|
-
* @param modelInfo - The model information for the client
|
|
1137
|
-
* @returns The created source file
|
|
1138
|
-
*/
|
|
1139
|
-
createApiClientFile(e) {
|
|
1140
|
-
let t = e.path;
|
|
1141
|
-
return this.context.currentContextAlias && (t = w(this.context.currentContextAlias, t)), t = w(t, `${e.name}ApiClient.ts`), this.context.logger.info(`Creating API client file: ${t}`), this.context.getOrCreateSourceFile(t);
|
|
1142
|
-
}
|
|
1143
|
-
/**
|
|
1144
|
-
* Generates a single API client class for the given tag and operations.
|
|
1145
|
-
* @param tag - The OpenAPI tag for the client
|
|
1146
|
-
* @param operations - Set of operations for this client
|
|
1147
|
-
*/
|
|
1148
|
-
generateApiClient(e, t) {
|
|
1149
|
-
const n = d(e.name);
|
|
1150
|
-
this.context.logger.info(
|
|
1151
|
-
`Generating API client class: ${n.name}ApiClient with ${t.size} operations`
|
|
1152
|
-
);
|
|
1153
|
-
const o = this.createApiClientFile(n);
|
|
1154
|
-
oe(o);
|
|
1155
|
-
const s = re(
|
|
1156
|
-
n.name + "ApiClient",
|
|
1157
|
-
o
|
|
1158
|
-
);
|
|
1159
|
-
x(s, e.description), se(s, this.apiMetadataCtorInitializer), this.context.logger.info(
|
|
1160
|
-
`Processing ${t.size} operations for ${n.name}ApiClient`
|
|
1161
|
-
), t.forEach((i) => {
|
|
1162
|
-
this.processOperation(e, o, s, i);
|
|
1163
|
-
}), this.context.logger.success(
|
|
1164
|
-
`Completed API client: ${n.name}ApiClient`
|
|
1165
|
-
);
|
|
1166
|
-
}
|
|
1167
|
-
/**
|
|
1168
|
-
* Generates a unique method name for the operation.
|
|
1169
|
-
* @param apiClientClass - The client class to check for existing methods
|
|
1170
|
-
* @param operation - The operation to generate a name for
|
|
1171
|
-
* @returns A unique camelCase method name
|
|
1172
|
-
*/
|
|
1173
|
-
getMethodName(e, t) {
|
|
1174
|
-
const n = t.operationId.split(".");
|
|
1175
|
-
for (let o = n.length - 1; o >= 0; o--) {
|
|
1176
|
-
const s = h(n.slice(o));
|
|
1177
|
-
if (!e.getMethod(s))
|
|
1178
|
-
return s;
|
|
1179
|
-
}
|
|
1180
|
-
return h(n);
|
|
1181
|
-
}
|
|
1182
|
-
/**
|
|
1183
|
-
* Resolves the request type for an operation based on its request body.
|
|
1184
|
-
* @param sourceFile - The source file to add imports to
|
|
1185
|
-
* @param operation - The operation to resolve the request type for
|
|
1186
|
-
* @returns The resolved request type string
|
|
1187
|
-
*/
|
|
1188
|
-
resolveRequestType(e, t) {
|
|
1189
|
-
if (!t.requestBody)
|
|
1190
|
-
return this.context.logger.info(
|
|
1191
|
-
`No request body found for operation ${t.operationId}, using default: ${this.defaultParameterRequestType}`
|
|
1192
|
-
), this.defaultParameterRequestType;
|
|
1193
|
-
let n;
|
|
1194
|
-
if (l(t.requestBody) ? (this.context.logger.info(
|
|
1195
|
-
`Extracting request body from reference for operation: ${t.operationId}`
|
|
1196
|
-
), n = k(
|
|
1197
|
-
t.requestBody,
|
|
1198
|
-
this.context.openAPI.components
|
|
1199
|
-
)) : n = t.requestBody, !n)
|
|
1200
|
-
return this.context.logger.info(
|
|
1201
|
-
`Request body extraction failed for operation ${t.operationId}, using default: ${this.defaultParameterRequestType}`
|
|
1202
|
-
), this.defaultParameterRequestType;
|
|
1203
|
-
if (n.content["multipart/form-data"])
|
|
1204
|
-
return this.context.logger.info(
|
|
1205
|
-
`Detected multipart/form-data content for operation ${t.operationId}, using ParameterRequest<FormData>`
|
|
1206
|
-
), "ParameterRequest<FormData>";
|
|
1207
|
-
if (n.content["application/json"]) {
|
|
1208
|
-
const o = n.content["application/json"].schema;
|
|
1209
|
-
if (l(o)) {
|
|
1210
|
-
const s = y(o);
|
|
1211
|
-
this.context.logger.info(
|
|
1212
|
-
`Adding import for request body model: ${s.name} from ${s.path}`
|
|
1213
|
-
), f(e, this.context.outputDir, s);
|
|
1214
|
-
const i = `ParameterRequest<${s.name}>`;
|
|
1215
|
-
return this.context.logger.info(
|
|
1216
|
-
`Resolved request type for operation ${t.operationId}: ${i}`
|
|
1217
|
-
), i;
|
|
1218
|
-
}
|
|
1219
|
-
}
|
|
1220
|
-
return this.context.logger.info(
|
|
1221
|
-
`Using default request type for operation ${t.operationId}: ${this.defaultParameterRequestType}`
|
|
1222
|
-
), this.defaultParameterRequestType;
|
|
1223
|
-
}
|
|
1224
|
-
/**
|
|
1225
|
-
* Resolves method parameters for an operation.
|
|
1226
|
-
* @param tag - The tag for parameter filtering
|
|
1227
|
-
* @param sourceFile - The source file to add imports to
|
|
1228
|
-
* @param operation - The operation to resolve parameters for
|
|
1229
|
-
* @returns Array of parameter declarations
|
|
1230
|
-
*/
|
|
1231
|
-
resolveParameters(e, t, n) {
|
|
1232
|
-
const o = Re(n, this.context.openAPI.components).filter((a) => !this.context.isIgnoreApiClientPathParameters(
|
|
1233
|
-
e.name,
|
|
1234
|
-
a.name
|
|
1235
|
-
));
|
|
1236
|
-
this.context.logger.info(
|
|
1237
|
-
`Found ${o.length} path parameters for operation ${n.operationId}`
|
|
1238
|
-
);
|
|
1239
|
-
const s = o.map((a) => {
|
|
1240
|
-
const c = X(a);
|
|
1241
|
-
return this.context.logger.info(
|
|
1242
|
-
`Adding path parameter: ${a.name} (type: ${c})`
|
|
1243
|
-
), {
|
|
1244
|
-
name: a.name,
|
|
1245
|
-
type: c,
|
|
1280
|
+
type: a,
|
|
1246
1281
|
hasQuestionToken: !1,
|
|
1247
1282
|
decorators: [
|
|
1248
1283
|
{
|
|
1249
1284
|
name: "path",
|
|
1250
|
-
arguments: [`'${
|
|
1285
|
+
arguments: [`'${i.name}'`]
|
|
1251
1286
|
}
|
|
1252
1287
|
]
|
|
1253
1288
|
};
|
|
1254
|
-
})
|
|
1255
|
-
return this.context.logger.info(
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1289
|
+
});
|
|
1290
|
+
return this.context.logger.info(
|
|
1291
|
+
`Adding command request parameter: commandRequest (type: CommandRequest<${o.name}>)`
|
|
1292
|
+
), s.push({
|
|
1293
|
+
name: "commandRequest",
|
|
1294
|
+
hasQuestionToken: Ae(n.schema.schema),
|
|
1295
|
+
type: `CommandRequest<${o.name}>`,
|
|
1259
1296
|
decorators: [
|
|
1260
1297
|
{
|
|
1261
1298
|
name: "request",
|
|
@@ -1263,7 +1300,7 @@ class ke {
|
|
|
1263
1300
|
}
|
|
1264
1301
|
]
|
|
1265
1302
|
}), this.context.logger.info(
|
|
1266
|
-
"Adding attributes parameter: Record<string, any>"
|
|
1303
|
+
"Adding attributes parameter: attributes (type: Record<string, any>)"
|
|
1267
1304
|
), s.push({
|
|
1268
1305
|
name: "attributes",
|
|
1269
1306
|
hasQuestionToken: !0,
|
|
@@ -1276,205 +1313,159 @@ class ke {
|
|
|
1276
1313
|
]
|
|
1277
1314
|
}), s;
|
|
1278
1315
|
}
|
|
1316
|
+
processCommandMethod(e, t, n, o, s) {
|
|
1317
|
+
this.context.logger.info(
|
|
1318
|
+
`Generating command method: ${h(o.name)} for command: ${o.name}`
|
|
1319
|
+
), this.context.logger.info(
|
|
1320
|
+
`Command method details: HTTP ${o.method}, path: ${o.path}, return type: ${s}`
|
|
1321
|
+
);
|
|
1322
|
+
const i = this.resolveParameters(e.aggregate.tag, t, o), a = n.addMethod({
|
|
1323
|
+
name: h(o.name),
|
|
1324
|
+
decorators: [
|
|
1325
|
+
{
|
|
1326
|
+
name: D(o.method),
|
|
1327
|
+
arguments: [`${this.getEndpointPath(o)}`]
|
|
1328
|
+
}
|
|
1329
|
+
],
|
|
1330
|
+
parameters: i,
|
|
1331
|
+
returnType: s,
|
|
1332
|
+
statements: [
|
|
1333
|
+
`throw autoGeneratedError(${i.map((c) => c.name).join(",")});`
|
|
1334
|
+
]
|
|
1335
|
+
});
|
|
1336
|
+
(o.summary || o.description) && this.context.logger.info(
|
|
1337
|
+
`Adding JSDoc documentation for method: ${h(o.name)}`
|
|
1338
|
+
), x(a, o.summary, o.description), this.context.logger.success(
|
|
1339
|
+
`Command method generated: ${h(o.name)}`
|
|
1340
|
+
);
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
class Qe {
|
|
1279
1344
|
/**
|
|
1280
|
-
*
|
|
1281
|
-
* @param
|
|
1282
|
-
* @param schema - The schema to resolve the return type for
|
|
1283
|
-
* @returns The resolved return type string
|
|
1345
|
+
* Creates a new QueryClientGenerator instance.
|
|
1346
|
+
* @param context - The generation context containing OpenAPI spec and project details
|
|
1284
1347
|
*/
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
const n = y(t);
|
|
1288
|
-
this.context.logger.info(
|
|
1289
|
-
`Adding import for response model: ${n.name} from ${n.path}`
|
|
1290
|
-
), f(e, this.context.outputDir, n);
|
|
1291
|
-
const o = `Promise<${n.name}>`;
|
|
1292
|
-
return this.context.logger.info(`Resolved reference return type: ${o}`), o;
|
|
1293
|
-
}
|
|
1294
|
-
if (!t.type)
|
|
1295
|
-
return this.context.logger.info(
|
|
1296
|
-
`Schema has no type, using default return type: ${this.defaultReturnType.type}`
|
|
1297
|
-
), this.defaultReturnType.type;
|
|
1298
|
-
if (b(t.type)) {
|
|
1299
|
-
const o = `Promise<${C(t.type)}>`;
|
|
1300
|
-
return this.context.logger.info(`Resolved primitive return type: ${o}`), o;
|
|
1301
|
-
}
|
|
1302
|
-
return this.context.logger.info(
|
|
1303
|
-
`Using default return type: ${this.defaultReturnType.type}`
|
|
1304
|
-
), this.defaultReturnType.type;
|
|
1348
|
+
constructor(e) {
|
|
1349
|
+
this.context = e;
|
|
1305
1350
|
}
|
|
1306
1351
|
/**
|
|
1307
|
-
*
|
|
1308
|
-
* @param sourceFile - The source file to add imports to
|
|
1309
|
-
* @param operation - The operation to resolve the return type for
|
|
1310
|
-
* @returns Object containing type and optional stream flag
|
|
1352
|
+
* Generates query client classes for all aggregates.
|
|
1311
1353
|
*/
|
|
1312
|
-
|
|
1313
|
-
const
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
if (l(s)) {
|
|
1331
|
-
const c = R(
|
|
1332
|
-
s,
|
|
1333
|
-
this.context.openAPI.components
|
|
1334
|
-
);
|
|
1335
|
-
if (O(c) && l(c.items)) {
|
|
1336
|
-
const g = y(c.items);
|
|
1337
|
-
this.context.logger.info(
|
|
1338
|
-
`Adding import for event stream model: ${g.name} from ${g.path}`
|
|
1339
|
-
), f(e, this.context.outputDir, g);
|
|
1340
|
-
const p = `Promise<JsonServerSentEventStream<${g.name.includes("ServerSentEvent") ? `${g.name}['data']` : g.name}>>`;
|
|
1341
|
-
return this.context.logger.info(
|
|
1342
|
-
`Resolved event stream return type for operation ${t.operationId}: ${p}`
|
|
1343
|
-
), {
|
|
1344
|
-
stream: !0,
|
|
1345
|
-
type: p
|
|
1346
|
-
};
|
|
1347
|
-
}
|
|
1348
|
-
}
|
|
1349
|
-
const a = "Promise<JsonServerSentEventStream<any>>";
|
|
1350
|
-
return this.context.logger.info(
|
|
1351
|
-
`Resolved generic event stream return type for operation ${t.operationId}: ${a}`
|
|
1352
|
-
), { stream: !0, type: a };
|
|
1353
|
-
}
|
|
1354
|
-
const i = Pe(n);
|
|
1355
|
-
if (i) {
|
|
1356
|
-
const a = this.resolveSchemaReturnType(
|
|
1357
|
-
e,
|
|
1358
|
-
i
|
|
1359
|
-
);
|
|
1360
|
-
return this.context.logger.info(
|
|
1361
|
-
`Resolved wildcard response return type for operation ${t.operationId}: ${a}`
|
|
1362
|
-
), { type: a };
|
|
1363
|
-
}
|
|
1364
|
-
return this.context.logger.info(
|
|
1365
|
-
`Using default return type for operation ${t.operationId}: ${this.defaultReturnType.type}`
|
|
1366
|
-
), this.defaultReturnType;
|
|
1354
|
+
generate() {
|
|
1355
|
+
const e = Array.from(this.context.contextAggregates.values()).reduce(
|
|
1356
|
+
(n, o) => n + o.size,
|
|
1357
|
+
0
|
|
1358
|
+
);
|
|
1359
|
+
this.context.logger.info("--- Generating Query Clients ---"), this.context.logger.progress(
|
|
1360
|
+
`Generating query clients for ${e} aggregates`
|
|
1361
|
+
);
|
|
1362
|
+
let t = 0;
|
|
1363
|
+
for (const [, n] of this.context.contextAggregates)
|
|
1364
|
+
n.forEach((o) => {
|
|
1365
|
+
t++, this.context.logger.progressWithCount(
|
|
1366
|
+
t,
|
|
1367
|
+
e,
|
|
1368
|
+
`Processing query client for aggregate: ${o.aggregate.aggregateName}`
|
|
1369
|
+
), this.processQueryClient(o);
|
|
1370
|
+
});
|
|
1371
|
+
this.context.logger.success("Query client generation completed");
|
|
1367
1372
|
}
|
|
1368
1373
|
/**
|
|
1369
|
-
*
|
|
1370
|
-
* @param
|
|
1371
|
-
* @param
|
|
1372
|
-
* @
|
|
1373
|
-
* @param operation - The operation to process
|
|
1374
|
+
* Creates or retrieves a source file for client generation.
|
|
1375
|
+
* @param aggregate - The aggregate metadata
|
|
1376
|
+
* @param fileName - The name of the client file
|
|
1377
|
+
* @returns The source file for the client
|
|
1374
1378
|
*/
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
const s = this.getMethodName(n, o.operation);
|
|
1380
|
-
this.context.logger.info(`Generated method name: ${s}`);
|
|
1381
|
-
const i = this.resolveParameters(
|
|
1379
|
+
createClientFilePath(e, t) {
|
|
1380
|
+
return se(
|
|
1381
|
+
this.context.project,
|
|
1382
|
+
this.context.outputDir,
|
|
1382
1383
|
e,
|
|
1383
|
-
t
|
|
1384
|
-
o.operation
|
|
1385
|
-
), a = this.resolveReturnType(t, o.operation), c = a.stream ? {
|
|
1386
|
-
name: N(o.method),
|
|
1387
|
-
arguments: [`'${o.path}'`, ne]
|
|
1388
|
-
} : {
|
|
1389
|
-
name: N(o.method),
|
|
1390
|
-
arguments: [`'${o.path}'`]
|
|
1391
|
-
};
|
|
1392
|
-
this.context.logger.info(
|
|
1393
|
-
`Creating method with ${i.length} parameters, return type: ${a.type}, stream: ${a.stream || !1}`
|
|
1384
|
+
t
|
|
1394
1385
|
);
|
|
1395
|
-
const g = n.addMethod({
|
|
1396
|
-
name: s,
|
|
1397
|
-
decorators: [c],
|
|
1398
|
-
parameters: i,
|
|
1399
|
-
returnType: a.type,
|
|
1400
|
-
statements: [
|
|
1401
|
-
`throw autoGeneratedError(${i.map((u) => u.name).join(",")});`
|
|
1402
|
-
]
|
|
1403
|
-
});
|
|
1404
|
-
x(
|
|
1405
|
-
g,
|
|
1406
|
-
o.operation.summary,
|
|
1407
|
-
o.operation.description
|
|
1408
|
-
), this.context.logger.success(`Operation method generated: ${s}`);
|
|
1409
1386
|
}
|
|
1410
1387
|
/**
|
|
1411
|
-
*
|
|
1412
|
-
* @param
|
|
1413
|
-
* @returns Map of operations grouped by tag name
|
|
1388
|
+
* Processes and generates query client classes for an aggregate.
|
|
1389
|
+
* @param aggregate - The aggregate definition
|
|
1414
1390
|
*/
|
|
1415
|
-
|
|
1416
|
-
this.
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1391
|
+
processQueryClient(e) {
|
|
1392
|
+
const t = this.createClientFilePath(
|
|
1393
|
+
e.aggregate,
|
|
1394
|
+
"queryClient"
|
|
1395
|
+
);
|
|
1396
|
+
this.context.logger.info(
|
|
1397
|
+
`Processing query client for aggregate: ${e.aggregate.aggregateName} in context: ${e.aggregate.contextAlias}`
|
|
1398
|
+
), this.context.logger.info(
|
|
1399
|
+
`Adding imports from ${P}: QueryClientFactory, QueryClientOptions, ResourceAttributionPathSpec`
|
|
1400
|
+
), t.addImportDeclaration({
|
|
1401
|
+
moduleSpecifier: P,
|
|
1402
|
+
namedImports: [
|
|
1403
|
+
"QueryClientFactory",
|
|
1404
|
+
"QueryClientOptions",
|
|
1405
|
+
"ResourceAttributionPathSpec"
|
|
1406
|
+
]
|
|
1407
|
+
});
|
|
1408
|
+
const n = "DEFAULT_QUERY_CLIENT_OPTIONS";
|
|
1409
|
+
this.context.logger.info(
|
|
1410
|
+
`Creating default query client options: ${n}`
|
|
1411
|
+
), t.addVariableStatement({
|
|
1412
|
+
declarationKind: v.Const,
|
|
1413
|
+
declarations: [
|
|
1414
|
+
{
|
|
1415
|
+
name: n,
|
|
1416
|
+
type: "QueryClientOptions",
|
|
1417
|
+
initializer: `{
|
|
1418
|
+
contextAlias: '${e.aggregate.contextAlias}',
|
|
1419
|
+
aggregateName: '${e.aggregate.aggregateName}',
|
|
1420
|
+
resourceAttribution: ${ze(e)},
|
|
1421
|
+
}`
|
|
1426
1422
|
}
|
|
1427
|
-
|
|
1423
|
+
],
|
|
1424
|
+
isExported: !1
|
|
1425
|
+
});
|
|
1426
|
+
const o = [];
|
|
1427
|
+
this.context.logger.info(
|
|
1428
|
+
`Processing ${e.events.size} domain events for aggregate: ${e.aggregate.aggregateName}`
|
|
1429
|
+
);
|
|
1430
|
+
for (const p of e.events.values()) {
|
|
1431
|
+
const u = d(p.schema.key);
|
|
1428
1432
|
this.context.logger.info(
|
|
1429
|
-
`
|
|
1430
|
-
);
|
|
1431
|
-
for (const a of i)
|
|
1432
|
-
a.operation.tags.forEach((c) => {
|
|
1433
|
-
const g = {
|
|
1434
|
-
...a,
|
|
1435
|
-
path: o
|
|
1436
|
-
};
|
|
1437
|
-
t.has(c) || t.set(c, /* @__PURE__ */ new Set()), t.get(c).add(g), n++;
|
|
1438
|
-
});
|
|
1433
|
+
`Adding import for event model: ${u.name} from path: ${u.path}`
|
|
1434
|
+
), f(t, this.context.outputDir, u), o.push(u);
|
|
1439
1435
|
}
|
|
1440
|
-
|
|
1441
|
-
`Grouped ${n} operations into ${t.size} tag groups`
|
|
1442
|
-
), t;
|
|
1443
|
-
}
|
|
1444
|
-
/**
|
|
1445
|
-
* Resolves valid API client tags from the OpenAPI specification.
|
|
1446
|
-
* Filters out system tags like 'wow' and 'Actuator' and aggregate tags.
|
|
1447
|
-
* @returns Map of valid API client tags
|
|
1448
|
-
*/
|
|
1449
|
-
resolveApiTags() {
|
|
1436
|
+
const s = "DOMAIN_EVENT_TYPES", i = o.map((p) => p.name).join(" | ");
|
|
1450
1437
|
this.context.logger.info(
|
|
1451
|
-
|
|
1438
|
+
`Creating domain event types union: ${s} = ${i}`
|
|
1439
|
+
), t.addTypeAlias({
|
|
1440
|
+
name: s,
|
|
1441
|
+
type: i
|
|
1442
|
+
});
|
|
1443
|
+
const a = `${h(e.aggregate.aggregateName)}QueryClientFactory`, c = d(e.state.key), l = d(e.fields.key);
|
|
1444
|
+
this.context.logger.info(
|
|
1445
|
+
`Adding import for state model: ${c.name} from path: ${c.path}`
|
|
1446
|
+
), f(t, this.context.outputDir, c), this.context.logger.info(
|
|
1447
|
+
`Adding import for fields model: ${l.name} from path: ${l.path}`
|
|
1448
|
+
), f(t, this.context.outputDir, l), this.context.logger.info(`Creating query client factory: ${a}`), t.addVariableStatement({
|
|
1449
|
+
declarationKind: v.Const,
|
|
1450
|
+
declarations: [
|
|
1451
|
+
{
|
|
1452
|
+
name: a,
|
|
1453
|
+
initializer: `new QueryClientFactory<${c.name}, ${l.name} | string, ${s}>(${n})`
|
|
1454
|
+
}
|
|
1455
|
+
],
|
|
1456
|
+
isExported: !0
|
|
1457
|
+
}), this.context.logger.success(
|
|
1458
|
+
`Query client generation completed for aggregate: ${e.aggregate.aggregateName}`
|
|
1452
1459
|
);
|
|
1453
|
-
const e = /* @__PURE__ */ new Map(), t = this.context.openAPI.tags?.length || 0;
|
|
1454
|
-
let n = 0;
|
|
1455
|
-
return this.context.openAPI.tags?.forEach((o) => {
|
|
1456
|
-
o.name != "wow" && o.name != "Actuator" && !this.isAggregateTag(o) ? (e.set(o.name, o), n++, this.context.logger.info(`Included API client tag: ${o.name}`)) : this.context.logger.info(
|
|
1457
|
-
`Excluded tag: ${o.name} (wow/Actuator/aggregate)`
|
|
1458
|
-
);
|
|
1459
|
-
}), this.context.logger.info(
|
|
1460
|
-
`Resolved ${n} API client tags from ${t} total tags`
|
|
1461
|
-
), e;
|
|
1462
|
-
}
|
|
1463
|
-
isAggregateTag(e) {
|
|
1464
|
-
for (const t of this.context.contextAggregates.values())
|
|
1465
|
-
for (const n of t)
|
|
1466
|
-
if (n.aggregate.tag.name === e.name)
|
|
1467
|
-
return !0;
|
|
1468
|
-
return !1;
|
|
1469
1460
|
}
|
|
1470
1461
|
}
|
|
1471
|
-
class
|
|
1462
|
+
class Ue {
|
|
1472
1463
|
/**
|
|
1473
1464
|
* Creates a new ClientGenerator instance.
|
|
1474
1465
|
* @param context - The generation context containing OpenAPI spec and project details
|
|
1475
1466
|
*/
|
|
1476
1467
|
constructor(e) {
|
|
1477
|
-
this.context = e, this.queryClientGenerator = new
|
|
1468
|
+
this.context = e, this.queryClientGenerator = new Qe(e), this.commandClientGenerator = new Le(e), this.apiClientGenerator = new ke(e);
|
|
1478
1469
|
}
|
|
1479
1470
|
queryClientGenerator;
|
|
1480
1471
|
commandClientGenerator;
|
|
@@ -1513,7 +1504,7 @@ class Qe {
|
|
|
1513
1504
|
);
|
|
1514
1505
|
}
|
|
1515
1506
|
}
|
|
1516
|
-
class
|
|
1507
|
+
class Je {
|
|
1517
1508
|
/** The ts-morph project instance used for code generation */
|
|
1518
1509
|
project;
|
|
1519
1510
|
/** The OpenAPI specification object */
|
|
@@ -1531,7 +1522,7 @@ class Le {
|
|
|
1531
1522
|
this.project = e.project, this.openAPI = e.openAPI, this.outputDir = e.outputDir, this.contextAggregates = e.contextAggregates, this.logger = e.logger, this.config = e.config ?? {}, this.currentContextAlias = this.openAPI.info["x-wow-context-alias"];
|
|
1532
1523
|
}
|
|
1533
1524
|
getOrCreateSourceFile(e) {
|
|
1534
|
-
return
|
|
1525
|
+
return te(this.project, this.outputDir, e);
|
|
1535
1526
|
}
|
|
1536
1527
|
isIgnoreApiClientPathParameters(e, t) {
|
|
1537
1528
|
return (this.config.apiClients?.[e]?.ignorePathParameters ?? this.defaultIgnorePathParameters).includes(t);
|
|
@@ -1540,14 +1531,14 @@ class Le {
|
|
|
1540
1531
|
return this.defaultIgnorePathParameters.includes(t);
|
|
1541
1532
|
}
|
|
1542
1533
|
}
|
|
1543
|
-
const
|
|
1544
|
-
class
|
|
1534
|
+
const Ve = "./fetcher-generator.config.json";
|
|
1535
|
+
class tt {
|
|
1545
1536
|
/**
|
|
1546
1537
|
* Creates a new CodeGenerator instance.
|
|
1547
1538
|
* @param options - Configuration options for code generation
|
|
1548
1539
|
*/
|
|
1549
1540
|
constructor(e) {
|
|
1550
|
-
this.options = e, this.project =
|
|
1541
|
+
this.options = e, this.project = new ce({ tsConfigFilePath: this.options.tsConfigFilePath }), this.options.logger.info("Project instance created with tsConfigFilePath: ", this.options.tsConfigFilePath);
|
|
1551
1542
|
}
|
|
1552
1543
|
project;
|
|
1553
1544
|
/**
|
|
@@ -1559,20 +1550,20 @@ class Ze {
|
|
|
1559
1550
|
this.options.logger.info(
|
|
1560
1551
|
"Starting code generation from OpenAPI specification"
|
|
1561
1552
|
), this.options.logger.info(`Input path: ${this.options.inputPath}`), this.options.logger.info(`Output directory: ${this.options.outputDir}`), this.options.logger.info("Parsing OpenAPI specification");
|
|
1562
|
-
const e = await
|
|
1553
|
+
const e = await Ie(this.options.inputPath);
|
|
1563
1554
|
this.options.logger.info("OpenAPI specification parsed successfully"), this.options.logger.info("Resolving bounded context aggregates");
|
|
1564
|
-
const n = new
|
|
1555
|
+
const n = new Me(e).resolve();
|
|
1565
1556
|
this.options.logger.info(
|
|
1566
1557
|
`Resolved ${n.size} bounded context aggregates`
|
|
1567
1558
|
);
|
|
1568
|
-
const o = this.options.configPath ??
|
|
1559
|
+
const o = this.options.configPath ?? Ve;
|
|
1569
1560
|
let s = {};
|
|
1570
1561
|
try {
|
|
1571
|
-
this.options.logger.info("Parsing configuration file:", o), s = await
|
|
1572
|
-
} catch (
|
|
1573
|
-
this.options.logger.info("Configuration file parsing failed ",
|
|
1562
|
+
this.options.logger.info("Parsing configuration file:", o), s = await Se(o);
|
|
1563
|
+
} catch (l) {
|
|
1564
|
+
this.options.logger.info("Configuration file parsing failed ", l);
|
|
1574
1565
|
}
|
|
1575
|
-
const i = new
|
|
1566
|
+
const i = new Je({
|
|
1576
1567
|
openAPI: e,
|
|
1577
1568
|
project: this.project,
|
|
1578
1569
|
outputDir: this.options.outputDir,
|
|
@@ -1580,7 +1571,7 @@ class Ze {
|
|
|
1580
1571
|
logger: this.options.logger,
|
|
1581
1572
|
config: s
|
|
1582
1573
|
});
|
|
1583
|
-
this.options.logger.info("Generating models"), new
|
|
1574
|
+
this.options.logger.info("Generating models"), new Fe(i).generate(), this.options.logger.info("Models generated successfully"), this.options.logger.info("Generating clients"), new Ue(i).generate(), this.options.logger.info("Clients generated successfully"), this.options.logger.info("Generating index files"), this.generateIndex(), this.options.logger.info("Index files generated successfully"), this.options.logger.info("Optimizing source files"), this.optimizeSourceFiles(), this.options.logger.info("Source files optimized successfully"), this.options.logger.info("Saving project to disk"), await this.project.save(), this.options.logger.info("Code generation completed successfully");
|
|
1584
1575
|
}
|
|
1585
1576
|
/**
|
|
1586
1577
|
* Generates index.ts files for all subdirectories in the output directory.
|
|
@@ -1660,7 +1651,7 @@ class Ze {
|
|
|
1660
1651
|
}
|
|
1661
1652
|
}
|
|
1662
1653
|
export {
|
|
1663
|
-
|
|
1664
|
-
|
|
1654
|
+
tt as CodeGenerator,
|
|
1655
|
+
Ve as DEFAULT_CONFIG_PATH
|
|
1665
1656
|
};
|
|
1666
1657
|
//# sourceMappingURL=index.js.map
|