@nestia/migrate 0.7.5 → 0.7.6
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.d.ts +9 -2
- package/lib/MigrateApplication.js +14 -8
- package/lib/MigrateApplication.js.map +1 -1
- package/lib/analyzers/MigrateAnalyzer.js +2 -2
- package/lib/analyzers/MigrateAnalyzer.js.map +1 -1
- package/lib/analyzers/{ControllerAnalyzer.d.ts → MigrateControllerAnalyzer.d.ts} +1 -1
- package/lib/analyzers/{ControllerAnalyzer.js → MigrateControllerAnalyzer.js} +11 -9
- package/lib/analyzers/MigrateControllerAnalyzer.js.map +1 -0
- package/lib/analyzers/{MethodAnalyzer.d.ts → MigrateMethodAnalyzer.d.ts} +1 -1
- package/lib/analyzers/{MethodAnalyzer.js → MigrateMethodAnalyzer.js} +26 -25
- package/lib/analyzers/MigrateMethodAnalyzer.js.map +1 -0
- package/lib/archivers/{FileArchiver.d.ts → MigrateFileArchiver.d.ts} +1 -1
- package/lib/archivers/{FileArchiver.js → MigrateFileArchiver.js} +6 -6
- package/lib/archivers/MigrateFileArchiver.js.map +1 -0
- package/lib/bundles/SDK_TEMPLATE.js +0 -5
- package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
- package/lib/executable/bundle.js +1 -0
- package/lib/executable/bundle.js.map +1 -1
- package/lib/internal/MigrateCommander.js +3 -3
- package/lib/internal/MigrateCommander.js.map +1 -1
- package/lib/programmers/{ApiFileProgrammer.d.ts → MigrateApiFileProgrammer.d.ts} +1 -1
- package/lib/programmers/MigrateApiFileProgrammer.js +28 -0
- package/lib/programmers/MigrateApiFileProgrammer.js.map +1 -0
- package/lib/programmers/{ApiFunctionProgrammer.d.ts → MigrateApiFunctionProgrammer.d.ts} +4 -4
- package/lib/programmers/{ApiFunctionProgrammer.js → MigrateApiFunctionProgrammer.js} +10 -10
- package/lib/programmers/MigrateApiFunctionProgrammer.js.map +1 -0
- package/lib/programmers/{ApiNamespaceProgrammer.d.ts → MigrateApiNamespaceProgrammer.d.ts} +3 -3
- package/lib/programmers/{ApiNamespaceProgrammer.js → MigrateApiNamespaceProgrammer.js} +19 -19
- package/lib/programmers/MigrateApiNamespaceProgrammer.js.map +1 -0
- package/lib/programmers/{ApiProgrammer.d.ts → MigrateApiProgrammer.d.ts} +1 -1
- package/lib/programmers/{ApiProgrammer.js → MigrateApiProgrammer.js} +25 -20
- package/lib/programmers/MigrateApiProgrammer.js.map +1 -0
- package/lib/programmers/{ApiSimulatationProgrammer.d.ts → MigrateApiSimulatationProgrammer.d.ts} +4 -4
- package/lib/programmers/{ApiSimulatationProgrammer.js → MigrateApiSimulatationProgrammer.js} +16 -16
- package/lib/programmers/MigrateApiSimulatationProgrammer.js.map +1 -0
- package/lib/programmers/{DtoProgrammer.d.ts → MigrateDtoProgrammer.d.ts} +3 -3
- package/lib/programmers/{DtoProgrammer.js → MigrateDtoProgrammer.js} +8 -8
- package/lib/programmers/MigrateDtoProgrammer.js.map +1 -0
- package/lib/programmers/{ImportProgrammer.d.ts → MigrateImportProgrammer.d.ts} +3 -3
- package/lib/programmers/{ImportProgrammer.js → MigrateImportProgrammer.js} +7 -5
- package/lib/programmers/MigrateImportProgrammer.js.map +1 -0
- package/lib/programmers/{NestControllerProgrammer.d.ts → MigrateNestControllerProgrammer.d.ts} +1 -1
- package/lib/programmers/{NestControllerProgrammer.js → MigrateNestControllerProgrammer.js} +11 -11
- package/lib/programmers/MigrateNestControllerProgrammer.js.map +1 -0
- package/lib/programmers/{NestMethodProgrammer.d.ts → MigrateNestMethodProgrammer.d.ts} +3 -3
- package/lib/programmers/{NestMethodProgrammer.js → MigrateNestMethodProgrammer.js} +13 -11
- package/lib/programmers/MigrateNestMethodProgrammer.js.map +1 -0
- package/lib/programmers/{NestModuleProgrammer.d.ts → MigrateNestModuleProgrammer.d.ts} +1 -1
- package/lib/programmers/{NestModuleProgrammer.js → MigrateNestModuleProgrammer.js} +8 -8
- package/lib/programmers/MigrateNestModuleProgrammer.js.map +1 -0
- package/lib/programmers/{NestProgrammer.d.ts → MigrateNestProgrammer.d.ts} +1 -1
- package/lib/programmers/{NestProgrammer.js → MigrateNestProgrammer.js} +17 -15
- package/lib/programmers/MigrateNestProgrammer.js.map +1 -0
- package/lib/programmers/{SchemaProgrammer.d.ts → MigrateSchemaProgrammer.d.ts} +3 -3
- package/lib/programmers/{SchemaProgrammer.js → MigrateSchemaProgrammer.js} +23 -23
- package/lib/programmers/MigrateSchemaProgrammer.js.map +1 -0
- package/lib/structures/IMigrateRoute.d.ts +1 -0
- package/lib/utils/FilePrinter.d.ts +1 -1
- package/lib/utils/FilePrinter.js +1 -1
- package/lib/utils/FilePrinter.js.map +1 -1
- package/lib/utils/{JsonTypeChecker.d.ts → SwaggerTypeChecker.d.ts} +1 -1
- package/lib/utils/SwaggerTypeChecker.js +34 -0
- package/lib/utils/SwaggerTypeChecker.js.map +1 -0
- package/package.json +68 -68
- package/src/IMigrateConfig.ts +4 -4
- package/src/MigrateApplication.ts +48 -35
- package/src/analyzers/MigrateAnalyzer.ts +13 -13
- package/src/analyzers/{ControllerAnalyzer.ts → MigrateControllerAnalyzer.ts} +122 -123
- package/src/analyzers/{MethodAnalyzer.ts → MigrateMethodAnalyzer.ts} +348 -347
- package/src/archivers/{FileArchiver.ts → MigrateFileArchiver.ts} +38 -38
- package/src/bundles/SDK_TEMPLATE.ts +0 -5
- package/src/executable/bundle.ts +109 -108
- package/src/executable/migrate.ts +7 -7
- package/src/internal/MigrateCommander.ts +51 -52
- package/src/internal/MigrateInquirer.ts +79 -79
- package/src/module.ts +4 -4
- package/src/programmers/{ApiFileProgrammer.ts → MigrateApiFileProgrammer.ts} +53 -53
- package/src/programmers/{ApiFunctionProgrammer.ts → MigrateApiFunctionProgrammer.ts} +203 -203
- package/src/programmers/{ApiNamespaceProgrammer.ts → MigrateApiNamespaceProgrammer.ts} +430 -418
- package/src/programmers/{ApiProgrammer.ts → MigrateApiProgrammer.ts} +132 -128
- package/src/programmers/{ApiSimulatationProgrammer.ts → MigrateApiSimulatationProgrammer.ts} +328 -328
- package/src/programmers/{DtoProgrammer.ts → MigrateDtoProgrammer.ts} +78 -74
- package/src/programmers/{ImportProgrammer.ts → MigrateImportProgrammer.ts} +116 -114
- package/src/programmers/{NestControllerProgrammer.ts → MigrateNestControllerProgrammer.ts} +50 -48
- package/src/programmers/{NestMethodProgrammer.ts → MigrateNestMethodProgrammer.ts} +249 -243
- package/src/programmers/{NestModuleProgrammer.ts → MigrateNestModuleProgrammer.ts} +62 -62
- package/src/programmers/{NestProgrammer.ts → MigrateNestProgrammer.ts} +74 -74
- package/src/programmers/{SchemaProgrammer.ts → MigrateSchemaProgrammer.ts} +257 -255
- package/src/structures/IMigrateProgram.ts +9 -9
- package/src/structures/IMigrateRoute.ts +46 -45
- package/src/structures/ISwaggeSchema.ts +90 -90
- package/src/structures/ISwaggerInfo.ts +80 -80
- package/src/utils/FilePrinter.ts +36 -36
- package/src/utils/SetupWizard.ts +12 -12
- package/src/utils/StringUtil.ts +60 -60
- package/src/utils/{JsonTypeChecker.ts → SwaggerTypeChecker.ts} +67 -67
- package/lib/analyzers/ControllerAnalyzer.js.map +0 -1
- package/lib/analyzers/MethodAnalyzer.js.map +0 -1
- package/lib/archivers/FileArchiver.js.map +0 -1
- package/lib/programmers/ApiFileProgrammer.js +0 -28
- package/lib/programmers/ApiFileProgrammer.js.map +0 -1
- package/lib/programmers/ApiFunctionProgrammer.js.map +0 -1
- package/lib/programmers/ApiNamespaceProgrammer.js.map +0 -1
- package/lib/programmers/ApiProgrammer.js.map +0 -1
- package/lib/programmers/ApiSimulatationProgrammer.js.map +0 -1
- package/lib/programmers/DtoProgrammer.js.map +0 -1
- package/lib/programmers/ImportProgrammer.js.map +0 -1
- package/lib/programmers/NestControllerProgrammer.js.map +0 -1
- package/lib/programmers/NestMethodProgrammer.js.map +0 -1
- package/lib/programmers/NestModuleProgrammer.js.map +0 -1
- package/lib/programmers/NestProgrammer.js.map +0 -1
- package/lib/programmers/SchemaProgrammer.js.map +0 -1
- package/lib/utils/JsonTypeChecker.js +0 -34
- package/lib/utils/JsonTypeChecker.js.map +0 -1
@@ -1,255 +1,257 @@
|
|
1
|
-
import ts from "typescript";
|
2
|
-
import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
|
3
|
-
import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
4
|
-
import { FormatCheatSheet } from "typia/lib/tags/internal/FormatCheatSheet";
|
5
|
-
import { Escaper } from "typia/lib/utils/Escaper";
|
6
|
-
|
7
|
-
import { ISwaggerSchema } from "../structures/ISwaggeSchema";
|
8
|
-
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
9
|
-
import { FilePrinter } from "../utils/FilePrinter";
|
10
|
-
import {
|
11
|
-
import {
|
12
|
-
|
13
|
-
export namespace
|
14
|
-
/* -----------------------------------------------------------
|
15
|
-
FACADE
|
16
|
-
----------------------------------------------------------- */
|
17
|
-
export const write =
|
18
|
-
(components: ISwaggerComponents) =>
|
19
|
-
(importer:
|
20
|
-
(schema: ISwaggerSchema): ts.TypeNode => {
|
21
|
-
const union: ts.TypeNode[] = [];
|
22
|
-
if (
|
23
|
-
return TypeFactory.keyword("any");
|
24
|
-
else if (
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
return
|
33
|
-
else if (
|
34
|
-
return
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
else if (
|
39
|
-
return
|
40
|
-
else if (
|
41
|
-
return
|
42
|
-
else if (
|
43
|
-
return
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
else if (
|
48
|
-
return writeUnion(components)(importer)(schema.
|
49
|
-
else
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
return
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
-----------------------------------------------------------
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
(
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
)
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
if (schema.
|
96
|
-
intersection.push(
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
if (schema.
|
127
|
-
intersection.push(importer.tag("
|
128
|
-
if (schema.
|
129
|
-
intersection.push(importer.tag("
|
130
|
-
if (schema.
|
131
|
-
intersection.push(importer.tag("
|
132
|
-
if (
|
133
|
-
schema.
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
-----------------------------------------------------------
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
(
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
if (schema.
|
158
|
-
intersection.push(importer.tag("
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
(
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
)
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
(
|
195
|
-
(
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
(
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
undefined,
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
-----------------------------------------------------------
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
(
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
(schema.
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
1
|
+
import ts from "typescript";
|
2
|
+
import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
|
3
|
+
import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
4
|
+
import { FormatCheatSheet } from "typia/lib/tags/internal/FormatCheatSheet";
|
5
|
+
import { Escaper } from "typia/lib/utils/Escaper";
|
6
|
+
|
7
|
+
import { ISwaggerSchema } from "../structures/ISwaggeSchema";
|
8
|
+
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
9
|
+
import { FilePrinter } from "../utils/FilePrinter";
|
10
|
+
import { SwaggerSwaggerChecker } from "../utils/SwaggerTypeChecker";
|
11
|
+
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
12
|
+
|
13
|
+
export namespace MigrateSchemaProgrammer {
|
14
|
+
/* -----------------------------------------------------------
|
15
|
+
FACADE
|
16
|
+
----------------------------------------------------------- */
|
17
|
+
export const write =
|
18
|
+
(components: ISwaggerComponents) =>
|
19
|
+
(importer: MigrateImportProgrammer) =>
|
20
|
+
(schema: ISwaggerSchema): ts.TypeNode => {
|
21
|
+
const union: ts.TypeNode[] = [];
|
22
|
+
if (SwaggerSwaggerChecker.isUnknown(schema))
|
23
|
+
return TypeFactory.keyword("any");
|
24
|
+
else if (SwaggerSwaggerChecker.isNullOnly(schema))
|
25
|
+
return createNode("null");
|
26
|
+
else if (SwaggerSwaggerChecker.isNullable(components)(schema))
|
27
|
+
union.push(createNode("null"));
|
28
|
+
|
29
|
+
const type: ts.TypeNode = (() => {
|
30
|
+
// ATOMIC
|
31
|
+
if (SwaggerSwaggerChecker.isBoolean(schema))
|
32
|
+
return writeBoolean(schema);
|
33
|
+
else if (SwaggerSwaggerChecker.isInteger(schema))
|
34
|
+
return writeInteger(importer)(schema);
|
35
|
+
else if (SwaggerSwaggerChecker.isNumber(schema))
|
36
|
+
return writeNumber(importer)(schema);
|
37
|
+
// INSTANCES
|
38
|
+
else if (SwaggerSwaggerChecker.isString(schema))
|
39
|
+
return writeString(importer)(schema);
|
40
|
+
else if (SwaggerSwaggerChecker.isArray(schema))
|
41
|
+
return writeArray(components)(importer)(schema);
|
42
|
+
else if (SwaggerSwaggerChecker.isObject(schema))
|
43
|
+
return writeObject(components)(importer)(schema);
|
44
|
+
else if (SwaggerSwaggerChecker.isReference(schema))
|
45
|
+
return writeReference(importer)(schema);
|
46
|
+
// NESTED UNION
|
47
|
+
else if (SwaggerSwaggerChecker.isAnyOf(schema))
|
48
|
+
return writeUnion(components)(importer)(schema.anyOf);
|
49
|
+
else if (SwaggerSwaggerChecker.isOneOf(schema))
|
50
|
+
return writeUnion(components)(importer)(schema.oneOf);
|
51
|
+
else return TypeFactory.keyword("any");
|
52
|
+
})();
|
53
|
+
union.push(type);
|
54
|
+
|
55
|
+
if (union.length === 0) return TypeFactory.keyword("any");
|
56
|
+
else if (union.length === 1) return union[0];
|
57
|
+
return ts.factory.createUnionTypeNode(union);
|
58
|
+
};
|
59
|
+
|
60
|
+
/* -----------------------------------------------------------
|
61
|
+
ATOMICS
|
62
|
+
----------------------------------------------------------- */
|
63
|
+
const writeBoolean = (schema: ISwaggerSchema.IBoolean): ts.TypeNode => {
|
64
|
+
if (schema.enum?.length)
|
65
|
+
return ts.factory.createLiteralTypeNode(
|
66
|
+
schema.enum[0] ? ts.factory.createTrue() : ts.factory.createFalse(),
|
67
|
+
);
|
68
|
+
return TypeFactory.keyword("boolean");
|
69
|
+
};
|
70
|
+
|
71
|
+
const writeInteger =
|
72
|
+
(importer: MigrateImportProgrammer) =>
|
73
|
+
(schema: ISwaggerSchema.IInteger): ts.TypeNode =>
|
74
|
+
writeNumeric(() => [
|
75
|
+
TypeFactory.keyword("number"),
|
76
|
+
importer.tag("Type", "int32"),
|
77
|
+
])(importer)(schema);
|
78
|
+
|
79
|
+
const writeNumber =
|
80
|
+
(importer: MigrateImportProgrammer) =>
|
81
|
+
(schema: ISwaggerSchema.INumber): ts.TypeNode =>
|
82
|
+
writeNumeric(() => [TypeFactory.keyword("number")])(importer)(schema);
|
83
|
+
|
84
|
+
const writeNumeric =
|
85
|
+
(factory: () => ts.TypeNode[]) =>
|
86
|
+
(importer: MigrateImportProgrammer) =>
|
87
|
+
(schema: ISwaggerSchema.IInteger | ISwaggerSchema.INumber): ts.TypeNode => {
|
88
|
+
if (schema.enum?.length)
|
89
|
+
return ts.factory.createUnionTypeNode(
|
90
|
+
schema.enum.map((i) =>
|
91
|
+
ts.factory.createLiteralTypeNode(ExpressionFactory.number(i)),
|
92
|
+
),
|
93
|
+
);
|
94
|
+
const intersection: ts.TypeNode[] = factory();
|
95
|
+
if (schema.default !== undefined)
|
96
|
+
intersection.push(importer.tag("Default", schema.default));
|
97
|
+
if (schema.minimum !== undefined)
|
98
|
+
intersection.push(
|
99
|
+
importer.tag(
|
100
|
+
schema.exclusiveMinimum ? "ExclusiveMinimum" : "Minimum",
|
101
|
+
schema.minimum,
|
102
|
+
),
|
103
|
+
);
|
104
|
+
if (schema.maximum !== undefined)
|
105
|
+
intersection.push(
|
106
|
+
importer.tag(
|
107
|
+
schema.exclusiveMaximum ? "ExclusiveMaximum" : "Maximum",
|
108
|
+
schema.maximum,
|
109
|
+
),
|
110
|
+
);
|
111
|
+
if (schema.multipleOf !== undefined)
|
112
|
+
intersection.push(importer.tag("MultipleOf", schema.multipleOf));
|
113
|
+
|
114
|
+
return intersection.length === 1
|
115
|
+
? intersection[0]
|
116
|
+
: ts.factory.createIntersectionTypeNode(intersection);
|
117
|
+
};
|
118
|
+
|
119
|
+
const writeString =
|
120
|
+
(importer: MigrateImportProgrammer) =>
|
121
|
+
(schema: ISwaggerSchema.IString): ts.TypeNode => {
|
122
|
+
if (schema.format === "binary")
|
123
|
+
return ts.factory.createTypeReferenceNode("File");
|
124
|
+
|
125
|
+
const intersection: ts.TypeNode[] = [TypeFactory.keyword("string")];
|
126
|
+
if (schema.default !== undefined)
|
127
|
+
intersection.push(importer.tag("Default", schema.default));
|
128
|
+
if (schema.minLength !== undefined)
|
129
|
+
intersection.push(importer.tag("MinLength", schema.minLength));
|
130
|
+
if (schema.maxLength !== undefined)
|
131
|
+
intersection.push(importer.tag("MaxLength", schema.maxLength));
|
132
|
+
if (schema.pattern !== undefined)
|
133
|
+
intersection.push(importer.tag("Pattern", schema.pattern));
|
134
|
+
if (
|
135
|
+
schema.format !== undefined &&
|
136
|
+
(FormatCheatSheet as Record<string, string>)[schema.format] !==
|
137
|
+
undefined
|
138
|
+
)
|
139
|
+
intersection.push(importer.tag("Format", schema.format));
|
140
|
+
return intersection.length === 1
|
141
|
+
? intersection[0]
|
142
|
+
: ts.factory.createIntersectionTypeNode(intersection);
|
143
|
+
};
|
144
|
+
|
145
|
+
/* -----------------------------------------------------------
|
146
|
+
INSTANCES
|
147
|
+
----------------------------------------------------------- */
|
148
|
+
const writeArray =
|
149
|
+
(components: ISwaggerComponents) =>
|
150
|
+
(importer: MigrateImportProgrammer) =>
|
151
|
+
(schema: ISwaggerSchema.IArray): ts.TypeNode => {
|
152
|
+
const intersection: ts.TypeNode[] = [
|
153
|
+
ts.factory.createArrayTypeNode(
|
154
|
+
write(components)(importer)(schema.items),
|
155
|
+
),
|
156
|
+
];
|
157
|
+
if (schema.minItems !== undefined)
|
158
|
+
intersection.push(importer.tag("MinItems", schema.minItems));
|
159
|
+
if (schema.maxItems !== undefined)
|
160
|
+
intersection.push(importer.tag("MaxItems", schema.maxItems));
|
161
|
+
return intersection.length === 1
|
162
|
+
? intersection[0]
|
163
|
+
: ts.factory.createIntersectionTypeNode(intersection);
|
164
|
+
};
|
165
|
+
|
166
|
+
const writeObject =
|
167
|
+
(components: ISwaggerComponents) =>
|
168
|
+
(importer: MigrateImportProgrammer) =>
|
169
|
+
(schema: ISwaggerSchema.IObject): ts.TypeNode => {
|
170
|
+
const regular = () =>
|
171
|
+
ts.factory.createTypeLiteralNode(
|
172
|
+
Object.entries(schema.properties ?? []).map(([key, value]) =>
|
173
|
+
writeRegularProperty(components)(importer)(schema.required ?? [])(
|
174
|
+
key,
|
175
|
+
value,
|
176
|
+
),
|
177
|
+
),
|
178
|
+
);
|
179
|
+
const dynamic = () =>
|
180
|
+
ts.factory.createTypeLiteralNode([
|
181
|
+
writeDynamicProperty(components)(importer)(
|
182
|
+
schema.additionalProperties as ISwaggerSchema,
|
183
|
+
),
|
184
|
+
]);
|
185
|
+
return !!schema.properties?.length &&
|
186
|
+
typeof schema.additionalProperties === "object"
|
187
|
+
? ts.factory.createIntersectionTypeNode([regular(), dynamic()])
|
188
|
+
: typeof schema.additionalProperties === "object"
|
189
|
+
? dynamic()
|
190
|
+
: regular();
|
191
|
+
};
|
192
|
+
|
193
|
+
const writeRegularProperty =
|
194
|
+
(components: ISwaggerComponents) =>
|
195
|
+
(importer: MigrateImportProgrammer) =>
|
196
|
+
(required: string[]) =>
|
197
|
+
(key: string, value: ISwaggerSchema) =>
|
198
|
+
FilePrinter.description(
|
199
|
+
ts.factory.createPropertySignature(
|
200
|
+
undefined,
|
201
|
+
Escaper.variable(key)
|
202
|
+
? ts.factory.createIdentifier(key)
|
203
|
+
: ts.factory.createStringLiteral(key),
|
204
|
+
required.includes(key)
|
205
|
+
? undefined
|
206
|
+
: ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
207
|
+
write(components)(importer)(value),
|
208
|
+
),
|
209
|
+
writeComment(value),
|
210
|
+
);
|
211
|
+
|
212
|
+
const writeDynamicProperty =
|
213
|
+
(components: ISwaggerComponents) =>
|
214
|
+
(importer: MigrateImportProgrammer) =>
|
215
|
+
(value: ISwaggerSchema) =>
|
216
|
+
FilePrinter.description(
|
217
|
+
ts.factory.createIndexSignature(
|
218
|
+
undefined,
|
219
|
+
[
|
220
|
+
ts.factory.createParameterDeclaration(
|
221
|
+
undefined,
|
222
|
+
undefined,
|
223
|
+
ts.factory.createIdentifier("key"),
|
224
|
+
undefined,
|
225
|
+
TypeFactory.keyword("string"),
|
226
|
+
),
|
227
|
+
],
|
228
|
+
write(components)(importer)(value),
|
229
|
+
),
|
230
|
+
writeComment(value),
|
231
|
+
);
|
232
|
+
|
233
|
+
const writeReference =
|
234
|
+
(importer: MigrateImportProgrammer) =>
|
235
|
+
(schema: ISwaggerSchema.IReference): ts.TypeReferenceNode =>
|
236
|
+
importer.dto(schema.$ref.split("/").at(-1)!);
|
237
|
+
|
238
|
+
/* -----------------------------------------------------------
|
239
|
+
UNIONS
|
240
|
+
----------------------------------------------------------- */
|
241
|
+
const writeUnion =
|
242
|
+
(components: ISwaggerComponents) =>
|
243
|
+
(importer: MigrateImportProgrammer) =>
|
244
|
+
(elements: ISwaggerSchema[]): ts.UnionTypeNode =>
|
245
|
+
ts.factory.createUnionTypeNode(elements.map(write(components)(importer)));
|
246
|
+
}
|
247
|
+
const createNode = (text: string) => ts.factory.createTypeReferenceNode(text);
|
248
|
+
const writeComment = (schema: ISwaggerSchema): string =>
|
249
|
+
[
|
250
|
+
...(schema.description?.length ? [schema.description] : []),
|
251
|
+
...(schema.description?.length &&
|
252
|
+
(schema.title !== undefined || schema.deprecated === true)
|
253
|
+
? [""]
|
254
|
+
: []),
|
255
|
+
...(schema.title !== undefined ? [`@title ${schema.title}`] : []),
|
256
|
+
...(schema.deprecated === true ? [`@deprecated`] : []),
|
257
|
+
].join("\n");
|
@@ -1,9 +1,9 @@
|
|
1
|
-
import { IMigrateConfig } from "../IMigrateConfig";
|
2
|
-
import { IMigrateController } from "./IMigrateController";
|
3
|
-
import { ISwagger } from "./ISwagger";
|
4
|
-
|
5
|
-
export interface IMigrateProgram {
|
6
|
-
config: IMigrateConfig;
|
7
|
-
controllers: IMigrateController[];
|
8
|
-
swagger: ISwagger;
|
9
|
-
}
|
1
|
+
import { IMigrateConfig } from "../IMigrateConfig";
|
2
|
+
import { IMigrateController } from "./IMigrateController";
|
3
|
+
import { ISwagger } from "./ISwagger";
|
4
|
+
|
5
|
+
export interface IMigrateProgram {
|
6
|
+
config: IMigrateConfig;
|
7
|
+
controllers: IMigrateController[];
|
8
|
+
swagger: ISwagger;
|
9
|
+
}
|
@@ -1,45 +1,46 @@
|
|
1
|
-
import { ISwaggerSchema } from "./ISwaggeSchema";
|
2
|
-
|
3
|
-
export interface IMigrateRoute {
|
4
|
-
name: string;
|
5
|
-
path: string;
|
6
|
-
method: string;
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
| "
|
36
|
-
| "application/
|
37
|
-
| "
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
}
|
1
|
+
import { ISwaggerSchema } from "./ISwaggeSchema";
|
2
|
+
|
3
|
+
export interface IMigrateRoute {
|
4
|
+
name: string;
|
5
|
+
path: string;
|
6
|
+
method: string;
|
7
|
+
accessor: string[];
|
8
|
+
parameters: IMigrateRoute.IParameter[];
|
9
|
+
headers: IMigrateRoute.IHeaders | null;
|
10
|
+
query: IMigrateRoute.IQuery | null;
|
11
|
+
body: IMigrateRoute.IBody | null;
|
12
|
+
success: IMigrateRoute.IBody | null;
|
13
|
+
exceptions: Record<string, IMigrateRoute.IException>;
|
14
|
+
description?: string;
|
15
|
+
tags: string[];
|
16
|
+
deprecated: boolean;
|
17
|
+
}
|
18
|
+
export namespace IMigrateRoute {
|
19
|
+
export interface IParameter {
|
20
|
+
key: string;
|
21
|
+
schema: ISwaggerSchema;
|
22
|
+
description?: string;
|
23
|
+
}
|
24
|
+
export interface IHeaders {
|
25
|
+
key: string;
|
26
|
+
schema: ISwaggerSchema;
|
27
|
+
}
|
28
|
+
export interface IQuery {
|
29
|
+
key: string;
|
30
|
+
schema: ISwaggerSchema;
|
31
|
+
}
|
32
|
+
export interface IBody {
|
33
|
+
key: string;
|
34
|
+
type:
|
35
|
+
| "text/plain"
|
36
|
+
| "application/json"
|
37
|
+
| "application/x-www-form-urlencoded"
|
38
|
+
| "multipart/form-data";
|
39
|
+
schema: ISwaggerSchema;
|
40
|
+
"x-nestia-encrypted"?: boolean;
|
41
|
+
}
|
42
|
+
export interface IException {
|
43
|
+
description?: string;
|
44
|
+
schema: ISwaggerSchema;
|
45
|
+
}
|
46
|
+
}
|