@nestia/migrate 0.14.3 → 0.15.0
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/lib/MigrateApplication.js +1045 -763
- package/lib/MigrateApplication.js.map +1 -1
- package/lib/bundles/NEST_TEMPLATE.js +2 -2
- package/lib/bundles/SDK_TEMPLATE.js +1 -1
- package/lib/programmers/MigrateNestMethodProgrammer.js +54 -11
- package/lib/programmers/MigrateNestMethodProgrammer.js.map +1 -1
- package/package.json +85 -85
- package/src/bundles/NEST_TEMPLATE.ts +2 -2
- package/src/bundles/SDK_TEMPLATE.ts +1 -1
- package/src/programmers/MigrateNestMethodProgrammer.ts +93 -13
@@ -2,6 +2,7 @@ import { OpenApi } from "@samchon/openapi";
|
|
2
2
|
import ts from "typescript";
|
3
3
|
import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
|
4
4
|
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
5
|
+
import { LiteralFactory } from "typia/lib/factories/LiteralFactory";
|
5
6
|
import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
6
7
|
|
7
8
|
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
@@ -87,6 +88,17 @@ export namespace MigrateNestMethodProgrammer {
|
|
87
88
|
name: instance,
|
88
89
|
}),
|
89
90
|
);
|
91
|
+
|
92
|
+
// EXAMPLES
|
93
|
+
const decorators: ts.Decorator[] = [];
|
94
|
+
if (route.success)
|
95
|
+
decorators.push(
|
96
|
+
...writeExampleDecorators("Response")(importer)(
|
97
|
+
route.success.media(),
|
98
|
+
),
|
99
|
+
);
|
100
|
+
|
101
|
+
// ROUTER
|
90
102
|
const router = (instance: string) =>
|
91
103
|
ts.factory.createDecorator(
|
92
104
|
ts.factory.createCallExpression(
|
@@ -97,8 +109,6 @@ export namespace MigrateNestMethodProgrammer {
|
|
97
109
|
[ts.factory.createStringLiteral(route.path)],
|
98
110
|
),
|
99
111
|
);
|
100
|
-
|
101
|
-
const decorators: ts.Decorator[] = [];
|
102
112
|
if (route.success?.["x-nestia-encrypted"])
|
103
113
|
decorators.push(router("EncryptedRoute"));
|
104
114
|
else if (route.success?.type === "text/plain")
|
@@ -142,8 +152,12 @@ export namespace MigrateNestMethodProgrammer {
|
|
142
152
|
isNaN(Number(key))
|
143
153
|
? ts.factory.createStringLiteral(key)
|
144
154
|
: ExpressionFactory.number(Number(key)),
|
145
|
-
...(value.description?.length
|
146
|
-
? [
|
155
|
+
...(value.response().description?.length
|
156
|
+
? [
|
157
|
+
ts.factory.createStringLiteral(
|
158
|
+
value.response().description!,
|
159
|
+
),
|
160
|
+
]
|
147
161
|
: []),
|
148
162
|
],
|
149
163
|
),
|
@@ -156,9 +170,10 @@ export namespace MigrateNestMethodProgrammer {
|
|
156
170
|
(components: OpenApi.IComponents) =>
|
157
171
|
(importer: MigrateImportProgrammer) =>
|
158
172
|
(route: IMigrateRoute): ts.ParameterDeclaration[] => [
|
159
|
-
...route.parameters.map((
|
173
|
+
...route.parameters.map((p) =>
|
160
174
|
ts.factory.createParameterDeclaration(
|
161
175
|
[
|
176
|
+
...writeExampleDecorators("Parameter")(importer)(p.parameter()),
|
162
177
|
ts.factory.createDecorator(
|
163
178
|
ts.factory.createCallExpression(
|
164
179
|
ts.factory.createIdentifier(
|
@@ -169,28 +184,36 @@ export namespace MigrateNestMethodProgrammer {
|
|
169
184
|
}),
|
170
185
|
),
|
171
186
|
undefined,
|
172
|
-
[ts.factory.createStringLiteral(key)],
|
187
|
+
[ts.factory.createStringLiteral(p.key)],
|
173
188
|
),
|
174
189
|
),
|
175
190
|
],
|
176
191
|
undefined,
|
177
|
-
key,
|
192
|
+
p.key,
|
178
193
|
undefined,
|
179
|
-
MigrateSchemaProgrammer.write(components)(importer)(
|
194
|
+
MigrateSchemaProgrammer.write(components)(importer)(p.schema),
|
180
195
|
),
|
181
196
|
),
|
182
197
|
...(route.headers
|
183
198
|
? [
|
184
199
|
writeDtoParameter({ method: "TypedHeaders", variable: "headers" })(
|
185
200
|
components,
|
186
|
-
)(importer)(
|
201
|
+
)(importer)({
|
202
|
+
schema: route.headers.schema,
|
203
|
+
example: route.headers.example(),
|
204
|
+
examples: route.headers.examples(),
|
205
|
+
}),
|
187
206
|
]
|
188
207
|
: []),
|
189
208
|
...(route.query
|
190
209
|
? [
|
191
210
|
writeDtoParameter({ method: "TypedQuery", variable: "query" })(
|
192
211
|
components,
|
193
|
-
)(importer)(
|
212
|
+
)(importer)({
|
213
|
+
schema: route.query.schema,
|
214
|
+
example: route.query.example(),
|
215
|
+
examples: route.query.examples(),
|
216
|
+
}),
|
194
217
|
]
|
195
218
|
: []),
|
196
219
|
...(route.body
|
@@ -208,7 +231,11 @@ export namespace MigrateNestMethodProgrammer {
|
|
208
231
|
? ["TypedFormData", "Body"]
|
209
232
|
: "TypedBody",
|
210
233
|
variable: "body",
|
211
|
-
})(components)(importer)(
|
234
|
+
})(components)(importer)({
|
235
|
+
schema: route.body.schema,
|
236
|
+
example: route.body.media().example,
|
237
|
+
examples: route.body.media().examples,
|
238
|
+
}),
|
212
239
|
]
|
213
240
|
: []),
|
214
241
|
];
|
@@ -217,7 +244,11 @@ export namespace MigrateNestMethodProgrammer {
|
|
217
244
|
(accessor: { method: string | [string, string]; variable: string }) =>
|
218
245
|
(components: OpenApi.IComponents) =>
|
219
246
|
(importer: MigrateImportProgrammer) =>
|
220
|
-
(
|
247
|
+
(props: {
|
248
|
+
schema: OpenApi.IJsonSchema;
|
249
|
+
example?: any;
|
250
|
+
examples?: Record<string, any>;
|
251
|
+
}): ts.ParameterDeclaration => {
|
221
252
|
const instance = ts.factory.createIdentifier(
|
222
253
|
importer.external({
|
223
254
|
type: "instance",
|
@@ -230,6 +261,7 @@ export namespace MigrateNestMethodProgrammer {
|
|
230
261
|
);
|
231
262
|
return ts.factory.createParameterDeclaration(
|
232
263
|
[
|
264
|
+
...writeExampleDecorators("Parameter")(importer)(props),
|
233
265
|
ts.factory.createDecorator(
|
234
266
|
ts.factory.createCallExpression(
|
235
267
|
typeof accessor.method === "string"
|
@@ -243,7 +275,55 @@ export namespace MigrateNestMethodProgrammer {
|
|
243
275
|
undefined,
|
244
276
|
accessor.variable,
|
245
277
|
undefined,
|
246
|
-
MigrateSchemaProgrammer.write(components)(importer)(schema),
|
278
|
+
MigrateSchemaProgrammer.write(components)(importer)(props.schema),
|
247
279
|
);
|
248
280
|
};
|
281
|
+
|
282
|
+
const writeExampleDecorators =
|
283
|
+
(kind: "Response" | "Parameter") =>
|
284
|
+
(importer: MigrateImportProgrammer) =>
|
285
|
+
(media: {
|
286
|
+
example?: any;
|
287
|
+
examples?: Record<string, any>;
|
288
|
+
}): ts.Decorator[] => [
|
289
|
+
...(media.example !== undefined
|
290
|
+
? [
|
291
|
+
ts.factory.createDecorator(
|
292
|
+
ts.factory.createCallExpression(
|
293
|
+
IdentifierFactory.access(
|
294
|
+
ts.factory.createIdentifier(
|
295
|
+
importer.external({
|
296
|
+
type: "instance",
|
297
|
+
library: "@nestia/core",
|
298
|
+
name: "SwaggerExample",
|
299
|
+
}),
|
300
|
+
),
|
301
|
+
)(kind),
|
302
|
+
[],
|
303
|
+
[LiteralFactory.generate(media.example)],
|
304
|
+
),
|
305
|
+
),
|
306
|
+
]
|
307
|
+
: []),
|
308
|
+
...Object.entries(media.examples ?? {}).map(([key, value]) =>
|
309
|
+
ts.factory.createDecorator(
|
310
|
+
ts.factory.createCallExpression(
|
311
|
+
IdentifierFactory.access(
|
312
|
+
ts.factory.createIdentifier(
|
313
|
+
importer.external({
|
314
|
+
type: "instance",
|
315
|
+
library: "@nestia/core",
|
316
|
+
name: "SwaggerExample",
|
317
|
+
}),
|
318
|
+
),
|
319
|
+
)(kind),
|
320
|
+
[],
|
321
|
+
[
|
322
|
+
ts.factory.createStringLiteral(key),
|
323
|
+
LiteralFactory.generate(value),
|
324
|
+
],
|
325
|
+
),
|
326
|
+
),
|
327
|
+
),
|
328
|
+
];
|
249
329
|
}
|