@nestia/migrate 0.12.0 → 0.13.0-dev.20240411
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 +3 -4
- package/lib/MigrateApplication.js +5160 -947
- package/lib/MigrateApplication.js.map +1 -1
- package/lib/analyzers/MigrateControllerAnalyzer.js +2 -1
- package/lib/analyzers/MigrateControllerAnalyzer.js.map +1 -1
- package/lib/analyzers/MigrateMethodAnalyzer.d.ts +2 -2
- package/lib/analyzers/MigrateMethodAnalyzer.js +60 -143
- package/lib/analyzers/MigrateMethodAnalyzer.js.map +1 -1
- package/lib/bundles/NEST_TEMPLATE.js +2 -2
- package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
- package/lib/bundles/SDK_TEMPLATE.js +1 -1
- package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
- package/lib/factories/TypeLiteralFactory.d.ts +4 -0
- package/lib/factories/TypeLiteralFactory.js +35 -0
- package/lib/factories/TypeLiteralFactory.js.map +1 -0
- package/lib/internal/MigrateCommander.js +2 -2
- package/lib/internal/MigrateCommander.js.map +1 -1
- package/lib/module.d.ts +0 -6
- package/lib/module.js +0 -6
- package/lib/module.js.map +1 -1
- package/lib/programmers/MigrateApiFileProgrammer.d.ts +2 -2
- package/lib/programmers/MigrateApiFileProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiFunctionProgrammer.d.ts +3 -3
- package/lib/programmers/MigrateApiFunctionProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiNamespaceProgrammer.d.ts +2 -2
- package/lib/programmers/MigrateApiNamespaceProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiProgrammer.js +2 -2
- package/lib/programmers/MigrateApiProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiSimulatationProgrammer.d.ts +3 -3
- package/lib/programmers/MigrateApiSimulatationProgrammer.js.map +1 -1
- package/lib/programmers/MigrateApiStartProgrammer.js +8 -8
- package/lib/programmers/MigrateApiStartProgrammer.js.map +1 -1
- package/lib/programmers/MigrateDtoProgrammer.d.ts +2 -2
- package/lib/programmers/MigrateDtoProgrammer.js.map +1 -1
- package/lib/programmers/MigrateE2eFileProgrammer.d.ts +3 -3
- package/lib/programmers/MigrateE2eFileProgrammer.js.map +1 -1
- package/lib/programmers/MigrateE2eProgrammer.js +1 -1
- package/lib/programmers/MigrateE2eProgrammer.js.map +1 -1
- package/lib/programmers/MigrateImportProgrammer.d.ts +1 -1
- package/lib/programmers/MigrateImportProgrammer.js +2 -4
- package/lib/programmers/MigrateImportProgrammer.js.map +1 -1
- package/lib/programmers/MigrateNestControllerProgrammer.d.ts +2 -2
- package/lib/programmers/MigrateNestControllerProgrammer.js.map +1 -1
- package/lib/programmers/MigrateNestMethodProgrammer.d.ts +2 -2
- package/lib/programmers/MigrateNestMethodProgrammer.js.map +1 -1
- package/lib/programmers/MigrateNestProgrammer.js +2 -2
- package/lib/programmers/MigrateNestProgrammer.js.map +1 -1
- package/lib/programmers/MigrateSchemaProgrammer.d.ts +2 -3
- package/lib/programmers/MigrateSchemaProgrammer.js +151 -28
- package/lib/programmers/MigrateSchemaProgrammer.js.map +1 -1
- package/lib/structures/IMigrateDto.d.ts +2 -2
- package/lib/structures/IMigrateProgram.d.ts +3 -4
- package/lib/structures/IMigrateRoute.d.ts +6 -6
- package/lib/utils/OpenApiTypeChecker.d.ts +15 -0
- package/lib/utils/OpenApiTypeChecker.js +28 -0
- package/lib/utils/OpenApiTypeChecker.js.map +1 -0
- package/package.json +4 -3
- package/src/MigrateApplication.ts +81 -86
- package/src/analyzers/MigrateControllerAnalyzer.ts +7 -5
- package/src/analyzers/MigrateMethodAnalyzer.ts +103 -179
- package/src/bundles/NEST_TEMPLATE.ts +2 -2
- package/src/bundles/SDK_TEMPLATE.ts +1 -1
- package/src/factories/TypeLiteralFactory.ts +57 -0
- package/src/internal/MigrateCommander.ts +4 -4
- package/src/module.ts +0 -6
- package/src/programmers/MigrateApiFileProgrammer.ts +2 -2
- package/src/programmers/MigrateApiFunctionProgrammer.ts +3 -3
- package/src/programmers/MigrateApiNamespaceProgrammer.ts +5 -5
- package/src/programmers/MigrateApiProgrammer.ts +4 -2
- package/src/programmers/MigrateApiSimulatationProgrammer.ts +4 -4
- package/src/programmers/MigrateApiStartProgrammer.ts +8 -8
- package/src/programmers/MigrateDtoProgrammer.ts +5 -6
- package/src/programmers/MigrateE2eFileProgrammer.ts +4 -4
- package/src/programmers/MigrateE2eProgrammer.ts +3 -3
- package/src/programmers/MigrateImportProgrammer.ts +117 -121
- package/src/programmers/MigrateNestControllerProgrammer.ts +2 -2
- package/src/programmers/MigrateNestMethodProgrammer.ts +6 -7
- package/src/programmers/MigrateNestProgrammer.ts +2 -2
- package/src/programmers/MigrateSchemaProgrammer.ts +355 -263
- package/src/structures/IMigrateDto.ts +2 -2
- package/src/structures/IMigrateProgram.ts +4 -4
- package/src/structures/IMigrateRoute.ts +6 -6
- package/src/utils/OpenApiTypeChecker.ts +73 -0
- package/lib/structures/ISwagger.d.ts +0 -18
- package/lib/structures/ISwagger.js +0 -3
- package/lib/structures/ISwagger.js.map +0 -1
- package/lib/structures/ISwaggerComponents.d.ts +0 -12
- package/lib/structures/ISwaggerComponents.js +0 -3
- package/lib/structures/ISwaggerComponents.js.map +0 -1
- package/lib/structures/ISwaggerInfo.d.ts +0 -71
- package/lib/structures/ISwaggerInfo.js +0 -3
- package/lib/structures/ISwaggerInfo.js.map +0 -1
- package/lib/structures/ISwaggerRoute.d.ts +0 -15
- package/lib/structures/ISwaggerRoute.js +0 -3
- package/lib/structures/ISwaggerRoute.js.map +0 -1
- package/lib/structures/ISwaggerRouteBodyContent.d.ts +0 -14
- package/lib/structures/ISwaggerRouteBodyContent.js +0 -3
- package/lib/structures/ISwaggerRouteBodyContent.js.map +0 -1
- package/lib/structures/ISwaggerRouteHeader.d.ts +0 -0
- package/lib/structures/ISwaggerRouteHeader.js +0 -2
- package/lib/structures/ISwaggerRouteHeader.js.map +0 -1
- package/lib/structures/ISwaggerRouteParameter.d.ts +0 -13
- package/lib/structures/ISwaggerRouteParameter.js +0 -3
- package/lib/structures/ISwaggerRouteParameter.js.map +0 -1
- package/lib/structures/ISwaggerRouteRequestBody.d.ts +0 -11
- package/lib/structures/ISwaggerRouteRequestBody.js +0 -3
- package/lib/structures/ISwaggerRouteRequestBody.js.map +0 -1
- package/lib/structures/ISwaggerRouteResponse.d.ts +0 -10
- package/lib/structures/ISwaggerRouteResponse.js +0 -3
- package/lib/structures/ISwaggerRouteResponse.js.map +0 -1
- package/lib/structures/ISwaggerSchema.d.ts +0 -75
- package/lib/structures/ISwaggerSchema.js +0 -3
- package/lib/structures/ISwaggerSchema.js.map +0 -1
- package/lib/structures/ISwaggerSecurityScheme.d.ts +0 -40
- package/lib/structures/ISwaggerSecurityScheme.js +0 -3
- package/lib/structures/ISwaggerSecurityScheme.js.map +0 -1
- package/lib/structures/ISwaggerV20.d.ts +0 -8
- package/lib/structures/ISwaggerV20.js +0 -3
- package/lib/structures/ISwaggerV20.js.map +0 -1
- package/lib/structures/ISwaggerV31.d.ts +0 -9
- package/lib/structures/ISwaggerV31.js +0 -3
- package/lib/structures/ISwaggerV31.js.map +0 -1
- package/lib/utils/OpenApiConverter.d.ts +0 -5
- package/lib/utils/OpenApiConverter.js +0 -1568
- package/lib/utils/OpenApiConverter.js.map +0 -1
- package/lib/utils/SwaggerComponentsExplorer.d.ts +0 -9
- package/lib/utils/SwaggerComponentsExplorer.js +0 -29
- package/lib/utils/SwaggerComponentsExplorer.js.map +0 -1
- package/lib/utils/SwaggerTypeChecker.d.ts +0 -16
- package/lib/utils/SwaggerTypeChecker.js +0 -34
- package/lib/utils/SwaggerTypeChecker.js.map +0 -1
- package/src/structures/ISwagger.ts +0 -23
- package/src/structures/ISwaggerComponents.ts +0 -13
- package/src/structures/ISwaggerInfo.ts +0 -80
- package/src/structures/ISwaggerRoute.ts +0 -20
- package/src/structures/ISwaggerRouteBodyContent.ts +0 -15
- package/src/structures/ISwaggerRouteHeader.ts +0 -0
- package/src/structures/ISwaggerRouteParameter.ts +0 -14
- package/src/structures/ISwaggerRouteRequestBody.ts +0 -12
- package/src/structures/ISwaggerRouteResponse.ts +0 -11
- package/src/structures/ISwaggerSchema.ts +0 -90
- package/src/structures/ISwaggerSecurityScheme.ts +0 -47
- package/src/structures/ISwaggerV20.ts +0 -10
- package/src/structures/ISwaggerV31.ts +0 -10
- package/src/utils/OpenApiConverter.ts +0 -19
- package/src/utils/SwaggerComponentsExplorer.ts +0 -43
- package/src/utils/SwaggerTypeChecker.ts +0 -67
@@ -1,263 +1,355 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import
|
4
|
-
import {
|
5
|
-
import {
|
6
|
-
|
7
|
-
|
8
|
-
import {
|
9
|
-
import {
|
10
|
-
import {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
(
|
19
|
-
(
|
20
|
-
|
21
|
-
const union: ts.TypeNode[] = [];
|
22
|
-
if (
|
23
|
-
return TypeFactory.keyword("any");
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
if (
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
else if (
|
37
|
-
return writeString(importer)(schema);
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
else if (
|
46
|
-
return
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
intersection
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
)
|
137
|
-
intersection.push(
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
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
|
-
|
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
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
2
|
+
import ts from "typescript";
|
3
|
+
import typia from "typia";
|
4
|
+
import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
5
|
+
import { FormatCheatSheet } from "typia/lib/tags/internal/FormatCheatSheet";
|
6
|
+
import { Escaper } from "typia/lib/utils/Escaper";
|
7
|
+
|
8
|
+
import { FilePrinter } from "../utils/FilePrinter";
|
9
|
+
import { OpenApiTypeChecker } from "../utils/OpenApiTypeChecker";
|
10
|
+
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
11
|
+
|
12
|
+
export namespace MigrateSchemaProgrammer {
|
13
|
+
/* -----------------------------------------------------------
|
14
|
+
FACADE
|
15
|
+
----------------------------------------------------------- */
|
16
|
+
export const write =
|
17
|
+
(components: OpenApi.IComponents) =>
|
18
|
+
(importer: MigrateImportProgrammer) =>
|
19
|
+
(schema: OpenApi.IJsonSchema): ts.TypeNode => {
|
20
|
+
// CONSIDER ANY TYPE CASE
|
21
|
+
const union: ts.TypeNode[] = [];
|
22
|
+
if (OpenApiTypeChecker.isUnknown(schema))
|
23
|
+
return TypeFactory.keyword("any");
|
24
|
+
|
25
|
+
// ITERATION
|
26
|
+
const type: ts.TypeNode = (() => {
|
27
|
+
// ATOMIC
|
28
|
+
if (OpenApiTypeChecker.isConstant(schema))
|
29
|
+
return writeConstant(importer)(schema);
|
30
|
+
else if (OpenApiTypeChecker.isBoolean(schema))
|
31
|
+
return writeBoolean(importer)(schema);
|
32
|
+
else if (OpenApiTypeChecker.isInteger(schema))
|
33
|
+
return writeInteger(importer)(schema);
|
34
|
+
else if (OpenApiTypeChecker.isNumber(schema))
|
35
|
+
return writeNumber(importer)(schema);
|
36
|
+
else if (OpenApiTypeChecker.isString(schema))
|
37
|
+
return writeString(importer)(schema);
|
38
|
+
// INSTANCES
|
39
|
+
else if (OpenApiTypeChecker.isArray(schema))
|
40
|
+
return writeArray(components)(importer)(schema);
|
41
|
+
else if (OpenApiTypeChecker.isTuple(schema))
|
42
|
+
return writeTuple(components)(importer)(schema);
|
43
|
+
else if (OpenApiTypeChecker.isObject(schema))
|
44
|
+
return writeObject(components)(importer)(schema);
|
45
|
+
else if (OpenApiTypeChecker.isReference(schema))
|
46
|
+
return writeReference(importer)(schema);
|
47
|
+
// UNION
|
48
|
+
else if (OpenApiTypeChecker.isOneOf(schema))
|
49
|
+
return writeUnion(components)(importer)(schema.oneOf);
|
50
|
+
else if (OpenApiTypeChecker.isNull(schema)) return createNode("null");
|
51
|
+
else return TypeFactory.keyword("any");
|
52
|
+
})();
|
53
|
+
union.push(type);
|
54
|
+
|
55
|
+
// DETERMINE
|
56
|
+
if (union.length === 0) return TypeFactory.keyword("any");
|
57
|
+
else if (union.length === 1) return union[0];
|
58
|
+
return ts.factory.createUnionTypeNode(union);
|
59
|
+
};
|
60
|
+
|
61
|
+
/* -----------------------------------------------------------
|
62
|
+
ATOMICS
|
63
|
+
----------------------------------------------------------- */
|
64
|
+
const writeConstant =
|
65
|
+
(importer: MigrateImportProgrammer) =>
|
66
|
+
(schema: OpenApi.IJsonSchema.IConstant): ts.TypeNode => {
|
67
|
+
const intersection: ts.TypeNode[] = [
|
68
|
+
ts.factory.createLiteralTypeNode(
|
69
|
+
typeof schema.const === "boolean"
|
70
|
+
? schema.const === true
|
71
|
+
? ts.factory.createTrue()
|
72
|
+
: ts.factory.createFalse()
|
73
|
+
: typeof schema.const === "number"
|
74
|
+
? schema.const < 0
|
75
|
+
? ts.factory.createPrefixUnaryExpression(
|
76
|
+
ts.SyntaxKind.MinusToken,
|
77
|
+
ts.factory.createNumericLiteral(-schema.const),
|
78
|
+
)
|
79
|
+
: ts.factory.createNumericLiteral(schema.const)
|
80
|
+
: ts.factory.createStringLiteral(schema.const),
|
81
|
+
),
|
82
|
+
];
|
83
|
+
writePlugin({
|
84
|
+
importer,
|
85
|
+
regular: typia.misc.literals<keyof OpenApi.IJsonSchema.IConstant>(),
|
86
|
+
intersection,
|
87
|
+
})(schema);
|
88
|
+
return intersection.length === 1
|
89
|
+
? intersection[0]
|
90
|
+
: ts.factory.createIntersectionTypeNode(intersection);
|
91
|
+
};
|
92
|
+
|
93
|
+
const writeBoolean =
|
94
|
+
(importer: MigrateImportProgrammer) =>
|
95
|
+
(schema: OpenApi.IJsonSchema.IBoolean): ts.TypeNode => {
|
96
|
+
const intersection: ts.TypeNode[] = [TypeFactory.keyword("boolean")];
|
97
|
+
writePlugin({
|
98
|
+
importer,
|
99
|
+
regular: typia.misc.literals<keyof OpenApi.IJsonSchema.IBoolean>(),
|
100
|
+
intersection,
|
101
|
+
})(schema);
|
102
|
+
return intersection.length === 1
|
103
|
+
? intersection[0]
|
104
|
+
: ts.factory.createIntersectionTypeNode(intersection);
|
105
|
+
};
|
106
|
+
|
107
|
+
const writeInteger =
|
108
|
+
(importer: MigrateImportProgrammer) =>
|
109
|
+
(schema: OpenApi.IJsonSchema.IInteger): ts.TypeNode =>
|
110
|
+
writeNumeric(() => [
|
111
|
+
TypeFactory.keyword("number"),
|
112
|
+
importer.tag("Type", "int32"),
|
113
|
+
])(importer)(schema);
|
114
|
+
|
115
|
+
const writeNumber =
|
116
|
+
(importer: MigrateImportProgrammer) =>
|
117
|
+
(schema: OpenApi.IJsonSchema.INumber): ts.TypeNode =>
|
118
|
+
writeNumeric(() => [TypeFactory.keyword("number")])(importer)(schema);
|
119
|
+
|
120
|
+
const writeNumeric =
|
121
|
+
(factory: () => ts.TypeNode[]) =>
|
122
|
+
(importer: MigrateImportProgrammer) =>
|
123
|
+
(
|
124
|
+
schema: OpenApi.IJsonSchema.IInteger | OpenApi.IJsonSchema.INumber,
|
125
|
+
): ts.TypeNode => {
|
126
|
+
const intersection: ts.TypeNode[] = factory();
|
127
|
+
if (schema.default !== undefined)
|
128
|
+
intersection.push(importer.tag("Default", schema.default));
|
129
|
+
if (schema.minimum !== undefined)
|
130
|
+
intersection.push(
|
131
|
+
importer.tag(
|
132
|
+
schema.exclusiveMinimum ? "ExclusiveMinimum" : "Minimum",
|
133
|
+
schema.minimum,
|
134
|
+
),
|
135
|
+
);
|
136
|
+
if (schema.maximum !== undefined)
|
137
|
+
intersection.push(
|
138
|
+
importer.tag(
|
139
|
+
schema.exclusiveMaximum ? "ExclusiveMaximum" : "Maximum",
|
140
|
+
schema.maximum,
|
141
|
+
),
|
142
|
+
);
|
143
|
+
if (schema.multipleOf !== undefined)
|
144
|
+
intersection.push(importer.tag("MultipleOf", schema.multipleOf));
|
145
|
+
writePlugin({
|
146
|
+
importer,
|
147
|
+
regular: typia.misc.literals<keyof OpenApi.IJsonSchema.INumber>(),
|
148
|
+
intersection,
|
149
|
+
})(schema);
|
150
|
+
return intersection.length === 1
|
151
|
+
? intersection[0]
|
152
|
+
: ts.factory.createIntersectionTypeNode(intersection);
|
153
|
+
};
|
154
|
+
|
155
|
+
const writeString =
|
156
|
+
(importer: MigrateImportProgrammer) =>
|
157
|
+
(schema: OpenApi.IJsonSchema.IString): ts.TypeNode => {
|
158
|
+
if (schema.format === "binary")
|
159
|
+
return ts.factory.createTypeReferenceNode("File");
|
160
|
+
|
161
|
+
const intersection: ts.TypeNode[] = [TypeFactory.keyword("string")];
|
162
|
+
if (schema.default !== undefined)
|
163
|
+
intersection.push(importer.tag("Default", schema.default));
|
164
|
+
if (schema.minLength !== undefined)
|
165
|
+
intersection.push(importer.tag("MinLength", schema.minLength));
|
166
|
+
if (schema.maxLength !== undefined)
|
167
|
+
intersection.push(importer.tag("MaxLength", schema.maxLength));
|
168
|
+
if (schema.pattern !== undefined)
|
169
|
+
intersection.push(importer.tag("Pattern", schema.pattern));
|
170
|
+
if (
|
171
|
+
schema.format !== undefined &&
|
172
|
+
(FormatCheatSheet as Record<string, string>)[schema.format] !==
|
173
|
+
undefined
|
174
|
+
)
|
175
|
+
intersection.push(importer.tag("Format", schema.format));
|
176
|
+
if (schema.contentMediaType !== undefined)
|
177
|
+
intersection.push(
|
178
|
+
importer.tag("ContentMediaType", schema.contentMediaType),
|
179
|
+
);
|
180
|
+
writePlugin({
|
181
|
+
importer,
|
182
|
+
regular: typia.misc.literals<keyof OpenApi.IJsonSchema.IString>(),
|
183
|
+
intersection,
|
184
|
+
})(schema);
|
185
|
+
return intersection.length === 1
|
186
|
+
? intersection[0]
|
187
|
+
: ts.factory.createIntersectionTypeNode(intersection);
|
188
|
+
};
|
189
|
+
|
190
|
+
/* -----------------------------------------------------------
|
191
|
+
INSTANCES
|
192
|
+
----------------------------------------------------------- */
|
193
|
+
const writeArray =
|
194
|
+
(components: OpenApi.IComponents) =>
|
195
|
+
(importer: MigrateImportProgrammer) =>
|
196
|
+
(schema: OpenApi.IJsonSchema.IArray): ts.TypeNode => {
|
197
|
+
const intersection: ts.TypeNode[] = [
|
198
|
+
ts.factory.createArrayTypeNode(
|
199
|
+
write(components)(importer)(schema.items),
|
200
|
+
),
|
201
|
+
];
|
202
|
+
if (schema.minItems !== undefined)
|
203
|
+
intersection.push(importer.tag("MinItems", schema.minItems));
|
204
|
+
if (schema.maxItems !== undefined)
|
205
|
+
intersection.push(importer.tag("MaxItems", schema.maxItems));
|
206
|
+
writePlugin({
|
207
|
+
importer,
|
208
|
+
regular: typia.misc.literals<keyof OpenApi.IJsonSchema.IArray>(),
|
209
|
+
intersection,
|
210
|
+
})(schema);
|
211
|
+
return intersection.length === 1
|
212
|
+
? intersection[0]
|
213
|
+
: ts.factory.createIntersectionTypeNode(intersection);
|
214
|
+
};
|
215
|
+
|
216
|
+
const writeTuple =
|
217
|
+
(components: OpenApi.IComponents) =>
|
218
|
+
(importer: MigrateImportProgrammer) =>
|
219
|
+
(schema: OpenApi.IJsonSchema.ITuple): ts.TypeNode => {
|
220
|
+
const tuple: ts.TypeNode = ts.factory.createTupleTypeNode([
|
221
|
+
...schema.prefixItems.map(write(components)(importer)),
|
222
|
+
...(typeof schema.additionalItems === "object" &&
|
223
|
+
schema.additionalItems !== null
|
224
|
+
? [
|
225
|
+
ts.factory.createRestTypeNode(
|
226
|
+
write(components)(importer)(schema.additionalItems),
|
227
|
+
),
|
228
|
+
]
|
229
|
+
: []),
|
230
|
+
]);
|
231
|
+
const intersection: ts.TypeNode[] = [tuple];
|
232
|
+
writePlugin({
|
233
|
+
importer,
|
234
|
+
regular: typia.misc.literals<keyof OpenApi.IJsonSchema.ITuple>(),
|
235
|
+
intersection,
|
236
|
+
})(schema);
|
237
|
+
return intersection.length === 1
|
238
|
+
? intersection[0]
|
239
|
+
: ts.factory.createIntersectionTypeNode(intersection);
|
240
|
+
};
|
241
|
+
|
242
|
+
const writeObject =
|
243
|
+
(components: OpenApi.IComponents) =>
|
244
|
+
(importer: MigrateImportProgrammer) =>
|
245
|
+
(schema: OpenApi.IJsonSchema.IObject): ts.TypeNode => {
|
246
|
+
const regular = () =>
|
247
|
+
ts.factory.createTypeLiteralNode(
|
248
|
+
Object.entries(schema.properties ?? []).map(([key, value]) =>
|
249
|
+
writeRegularProperty(components)(importer)(schema.required ?? [])(
|
250
|
+
key,
|
251
|
+
value,
|
252
|
+
),
|
253
|
+
),
|
254
|
+
);
|
255
|
+
const dynamic = () =>
|
256
|
+
ts.factory.createTypeLiteralNode([
|
257
|
+
writeDynamicProperty(components)(importer)(
|
258
|
+
schema.additionalProperties as OpenApi.IJsonSchema,
|
259
|
+
),
|
260
|
+
]);
|
261
|
+
return !!schema.properties?.length &&
|
262
|
+
typeof schema.additionalProperties === "object"
|
263
|
+
? ts.factory.createIntersectionTypeNode([regular(), dynamic()])
|
264
|
+
: typeof schema.additionalProperties === "object"
|
265
|
+
? dynamic()
|
266
|
+
: regular();
|
267
|
+
};
|
268
|
+
|
269
|
+
const writeRegularProperty =
|
270
|
+
(components: OpenApi.IComponents) =>
|
271
|
+
(importer: MigrateImportProgrammer) =>
|
272
|
+
(required: string[]) =>
|
273
|
+
(key: string, value: OpenApi.IJsonSchema) =>
|
274
|
+
FilePrinter.description(
|
275
|
+
ts.factory.createPropertySignature(
|
276
|
+
undefined,
|
277
|
+
Escaper.variable(key)
|
278
|
+
? ts.factory.createIdentifier(key)
|
279
|
+
: ts.factory.createStringLiteral(key),
|
280
|
+
required.includes(key)
|
281
|
+
? undefined
|
282
|
+
: ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
283
|
+
write(components)(importer)(value),
|
284
|
+
),
|
285
|
+
writeComment(value),
|
286
|
+
);
|
287
|
+
|
288
|
+
const writeDynamicProperty =
|
289
|
+
(components: OpenApi.IComponents) =>
|
290
|
+
(importer: MigrateImportProgrammer) =>
|
291
|
+
(value: OpenApi.IJsonSchema) =>
|
292
|
+
FilePrinter.description(
|
293
|
+
ts.factory.createIndexSignature(
|
294
|
+
undefined,
|
295
|
+
[
|
296
|
+
ts.factory.createParameterDeclaration(
|
297
|
+
undefined,
|
298
|
+
undefined,
|
299
|
+
ts.factory.createIdentifier("key"),
|
300
|
+
undefined,
|
301
|
+
TypeFactory.keyword("string"),
|
302
|
+
),
|
303
|
+
],
|
304
|
+
write(components)(importer)(value),
|
305
|
+
),
|
306
|
+
writeComment(value),
|
307
|
+
);
|
308
|
+
|
309
|
+
const writeReference =
|
310
|
+
(importer: MigrateImportProgrammer) =>
|
311
|
+
(
|
312
|
+
schema: OpenApi.IJsonSchema.IReference,
|
313
|
+
): ts.TypeReferenceNode | ts.KeywordTypeNode => {
|
314
|
+
if (schema.$ref.startsWith("#/components/schemas") === false)
|
315
|
+
return TypeFactory.keyword("any");
|
316
|
+
const name: string = schema.$ref.split("/").at(-1)!;
|
317
|
+
return name === ""
|
318
|
+
? TypeFactory.keyword("any")
|
319
|
+
: importer.dto(schema.$ref.split("/").at(-1)!);
|
320
|
+
};
|
321
|
+
|
322
|
+
/* -----------------------------------------------------------
|
323
|
+
UNIONS
|
324
|
+
----------------------------------------------------------- */
|
325
|
+
const writeUnion =
|
326
|
+
(components: OpenApi.IComponents) =>
|
327
|
+
(importer: MigrateImportProgrammer) =>
|
328
|
+
(elements: OpenApi.IJsonSchema[]): ts.UnionTypeNode =>
|
329
|
+
ts.factory.createUnionTypeNode(elements.map(write(components)(importer)));
|
330
|
+
}
|
331
|
+
const createNode = (text: string) => ts.factory.createTypeReferenceNode(text);
|
332
|
+
const writeComment = (schema: OpenApi.IJsonSchema): string =>
|
333
|
+
[
|
334
|
+
...(schema.description?.length ? [schema.description] : []),
|
335
|
+
...(schema.description?.length &&
|
336
|
+
(schema.title !== undefined || schema.deprecated === true)
|
337
|
+
? [""]
|
338
|
+
: []),
|
339
|
+
...(schema.title !== undefined ? [`@title ${schema.title}`] : []),
|
340
|
+
...(schema.deprecated === true ? [`@deprecated`] : []),
|
341
|
+
].join("\n");
|
342
|
+
const writePlugin =
|
343
|
+
(props: {
|
344
|
+
importer: MigrateImportProgrammer;
|
345
|
+
regular: string[];
|
346
|
+
intersection: ts.TypeNode[];
|
347
|
+
}) =>
|
348
|
+
(schema: any) => {
|
349
|
+
const extra: any = {};
|
350
|
+
for (const [key, value] of Object.entries(schema))
|
351
|
+
if (value !== undefined && false === props.regular.includes(key))
|
352
|
+
extra[key] = value;
|
353
|
+
if (Object.keys(extra).length !== 0)
|
354
|
+
props.intersection.push(props.importer.tag("JsonSchemaPlugin", extra));
|
355
|
+
};
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import {
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
2
2
|
|
3
3
|
export interface IMigrateDto {
|
4
4
|
name: string;
|
5
5
|
location: string;
|
6
|
-
schema:
|
6
|
+
schema: OpenApi.IJsonSchema | null;
|
7
7
|
children: IMigrateDto[];
|
8
8
|
}
|