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