@nestia/migrate 4.5.2 → 4.6.1-dev.20250117
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/README.md +87 -87
- package/lib/bundles/NEST_TEMPLATE.js +66 -66
- package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
- package/lib/bundles/SDK_TEMPLATE.js +30 -30
- package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
- package/lib/index.mjs +92 -92
- package/lib/index.mjs.map +1 -1
- package/lib/utils/openapi-down-convert/converter.js +2 -2
- package/package.json +9 -9
- package/src/MigrateApplication.ts +107 -107
- package/src/analyzers/MigrateApplicationAnalyzer.ts +18 -18
- package/src/analyzers/MigrateControllerAnalyzer.ts +51 -51
- package/src/archivers/MigrateFileArchiver.ts +38 -38
- package/src/bundles/NEST_TEMPLATE.ts +66 -66
- package/src/bundles/SDK_TEMPLATE.ts +30 -30
- package/src/executable/bundle.js +125 -125
- package/src/executable/migrate.ts +7 -7
- package/src/factories/TypeLiteralFactory.ts +57 -57
- package/src/index.ts +4 -4
- package/src/internal/MigrateCommander.ts +86 -86
- package/src/internal/MigrateInquirer.ts +89 -89
- package/src/module.ts +8 -8
- package/src/programmers/MigrateApiFileProgrammer.ts +49 -49
- package/src/programmers/MigrateApiFunctionProgrammer.ts +210 -210
- package/src/programmers/MigrateApiNamespaceProgrammer.ts +417 -417
- package/src/programmers/MigrateApiProgrammer.ts +103 -103
- package/src/programmers/MigrateApiSimulatationProgrammer.ts +324 -324
- package/src/programmers/MigrateApiStartProgrammer.ts +194 -194
- package/src/programmers/MigrateDtoProgrammer.ts +87 -87
- package/src/programmers/MigrateE2eFileProgrammer.ts +117 -117
- package/src/programmers/MigrateE2eProgrammer.ts +34 -34
- package/src/programmers/MigrateImportProgrammer.ts +118 -118
- package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
- package/src/programmers/MigrateNestMethodProgrammer.ts +393 -393
- package/src/programmers/MigrateNestModuleProgrammer.ts +65 -65
- package/src/programmers/MigrateNestProgrammer.ts +81 -81
- package/src/programmers/MigrateSchemaProgrammer.ts +373 -373
- package/src/structures/IHttpMigrateController.ts +8 -8
- package/src/structures/IHttpMigrateDto.ts +8 -8
- package/src/structures/IHttpMigrateFile.ts +5 -5
- package/src/structures/IHttpMigrateProgram.ts +27 -27
- package/src/structures/IHttpMigrateRoute.ts +1 -1
- package/src/structures/IHttpMigrateSchema.ts +4 -4
- package/src/utils/FilePrinter.ts +36 -36
- package/src/utils/MapUtil.ts +13 -13
- package/src/utils/OpenApiTypeChecker.ts +73 -73
- package/src/utils/SetupWizard.ts +12 -12
- package/src/utils/StringUtil.ts +113 -113
- package/src/utils/openapi-down-convert/RefVisitor.ts +139 -139
- package/src/utils/openapi-down-convert/converter.ts +527 -527
@@ -1,194 +1,194 @@
|
|
1
|
-
import { OpenApi } from "@samchon/openapi";
|
2
|
-
import ts from "typescript";
|
3
|
-
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
4
|
-
import { StatementFactory } from "typia/lib/factories/StatementFactory";
|
5
|
-
|
6
|
-
import { IHttpMigrateFile } from "../structures/IHttpMigrateFile";
|
7
|
-
import { IHttpMigrateProgram } from "../structures/IHttpMigrateProgram";
|
8
|
-
import { IHttpMigrateRoute } from "../structures/IHttpMigrateRoute";
|
9
|
-
import { FilePrinter } from "../utils/FilePrinter";
|
10
|
-
import { MigrateE2eFunctionProgrammer } from "./MigrateE2eFileProgrammer";
|
11
|
-
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
12
|
-
|
13
|
-
export namespace MigrateApiStartProgrammer {
|
14
|
-
export const write = (program: IHttpMigrateProgram): IHttpMigrateFile => {
|
15
|
-
const importer: MigrateImportProgrammer = new MigrateImportProgrammer();
|
16
|
-
const main: ts.VariableStatement = writeMain(program)(program.document)(
|
17
|
-
importer,
|
18
|
-
)(pick(program.routes));
|
19
|
-
const statements: ts.Statement[] = [
|
20
|
-
...importer.toStatements(
|
21
|
-
(name) => `@ORGANIZATION/PROJECT-api/lib/structures/${name}`,
|
22
|
-
),
|
23
|
-
FilePrinter.newLine(),
|
24
|
-
ts.factory.createImportDeclaration(
|
25
|
-
undefined,
|
26
|
-
ts.factory.createImportClause(
|
27
|
-
false,
|
28
|
-
undefined,
|
29
|
-
ts.factory.createNamedImports([
|
30
|
-
ts.factory.createImportSpecifier(
|
31
|
-
false,
|
32
|
-
undefined,
|
33
|
-
ts.factory.createIdentifier("TestGlobal"),
|
34
|
-
),
|
35
|
-
]),
|
36
|
-
),
|
37
|
-
ts.factory.createStringLiteral("./TestGlobal"),
|
38
|
-
undefined,
|
39
|
-
),
|
40
|
-
FilePrinter.newLine(),
|
41
|
-
main,
|
42
|
-
ts.factory.createExpressionStatement(writeStarter()),
|
43
|
-
];
|
44
|
-
return {
|
45
|
-
location: `test`,
|
46
|
-
file: "start.ts",
|
47
|
-
content: FilePrinter.write({ statements }),
|
48
|
-
};
|
49
|
-
};
|
50
|
-
|
51
|
-
const writeMain =
|
52
|
-
(config: IHttpMigrateProgram.IConfig) =>
|
53
|
-
(document: OpenApi.IDocument) =>
|
54
|
-
(importer: MigrateImportProgrammer) =>
|
55
|
-
(route: IHttpMigrateRoute): ts.VariableStatement =>
|
56
|
-
StatementFactory.constant({
|
57
|
-
name: "main",
|
58
|
-
value: ts.factory.createArrowFunction(
|
59
|
-
[ts.factory.createToken(ts.SyntaxKind.AsyncKeyword)],
|
60
|
-
undefined,
|
61
|
-
[],
|
62
|
-
undefined,
|
63
|
-
undefined,
|
64
|
-
ts.factory.createBlock(
|
65
|
-
[
|
66
|
-
writeConnection(config)(document)(importer),
|
67
|
-
...MigrateE2eFunctionProgrammer.writeBody(document.components)(
|
68
|
-
importer,
|
69
|
-
)(route),
|
70
|
-
],
|
71
|
-
true,
|
72
|
-
),
|
73
|
-
),
|
74
|
-
});
|
75
|
-
|
76
|
-
const writeConnection =
|
77
|
-
(config: IHttpMigrateProgram.IConfig) =>
|
78
|
-
(document: OpenApi.IDocument) =>
|
79
|
-
(importer: MigrateImportProgrammer): ts.VariableStatement =>
|
80
|
-
ts.factory.createVariableStatement(
|
81
|
-
undefined,
|
82
|
-
ts.factory.createVariableDeclarationList(
|
83
|
-
[
|
84
|
-
ts.factory.createVariableDeclaration(
|
85
|
-
"connection",
|
86
|
-
undefined,
|
87
|
-
ts.factory.createTypeReferenceNode(
|
88
|
-
ts.factory.createQualifiedName(
|
89
|
-
ts.factory.createIdentifier(
|
90
|
-
importer.external({
|
91
|
-
type: "default",
|
92
|
-
library: "@ORGANIZATION/PROJECT-api",
|
93
|
-
name: "api",
|
94
|
-
}),
|
95
|
-
),
|
96
|
-
ts.factory.createIdentifier("IConnection"),
|
97
|
-
),
|
98
|
-
),
|
99
|
-
ts.factory.createObjectLiteralExpression(
|
100
|
-
[
|
101
|
-
ts.factory.createSpreadAssignment(
|
102
|
-
ts.factory.createCallExpression(
|
103
|
-
ts.factory.createPropertyAccessExpression(
|
104
|
-
ts.factory.createIdentifier("TestGlobal"),
|
105
|
-
"connection",
|
106
|
-
),
|
107
|
-
undefined,
|
108
|
-
undefined,
|
109
|
-
),
|
110
|
-
),
|
111
|
-
...(document.servers?.[0]?.url?.length
|
112
|
-
? [
|
113
|
-
ts.factory.createPropertyAssignment(
|
114
|
-
"host",
|
115
|
-
ts.factory.createStringLiteral(
|
116
|
-
document.servers[0].url,
|
117
|
-
),
|
118
|
-
),
|
119
|
-
]
|
120
|
-
: []),
|
121
|
-
...(config.simulate === true
|
122
|
-
? [
|
123
|
-
ts.factory.createPropertyAssignment(
|
124
|
-
"simulate",
|
125
|
-
ts.factory.createTrue(),
|
126
|
-
),
|
127
|
-
]
|
128
|
-
: []),
|
129
|
-
],
|
130
|
-
true,
|
131
|
-
),
|
132
|
-
),
|
133
|
-
],
|
134
|
-
ts.NodeFlags.Const,
|
135
|
-
),
|
136
|
-
);
|
137
|
-
|
138
|
-
const writeStarter = (): ts.CallExpression =>
|
139
|
-
ts.factory.createCallExpression(
|
140
|
-
ts.factory.createPropertyAccessExpression(
|
141
|
-
ts.factory.createCallExpression(
|
142
|
-
ts.factory.createIdentifier("main"),
|
143
|
-
undefined,
|
144
|
-
undefined,
|
145
|
-
),
|
146
|
-
"catch",
|
147
|
-
),
|
148
|
-
undefined,
|
149
|
-
[
|
150
|
-
ts.factory.createArrowFunction(
|
151
|
-
undefined,
|
152
|
-
undefined,
|
153
|
-
[IdentifierFactory.parameter("exp")],
|
154
|
-
undefined,
|
155
|
-
undefined,
|
156
|
-
ts.factory.createBlock(
|
157
|
-
[
|
158
|
-
ts.factory.createExpressionStatement(
|
159
|
-
ts.factory.createCallExpression(
|
160
|
-
ts.factory.createPropertyAccessExpression(
|
161
|
-
ts.factory.createIdentifier("console"),
|
162
|
-
"log",
|
163
|
-
),
|
164
|
-
undefined,
|
165
|
-
[ts.factory.createIdentifier("exp")],
|
166
|
-
),
|
167
|
-
),
|
168
|
-
ts.factory.createExpressionStatement(
|
169
|
-
ts.factory.createCallExpression(
|
170
|
-
ts.factory.createPropertyAccessExpression(
|
171
|
-
ts.factory.createIdentifier("process"),
|
172
|
-
"exit",
|
173
|
-
),
|
174
|
-
undefined,
|
175
|
-
[
|
176
|
-
ts.factory.createPrefixMinus(
|
177
|
-
ts.factory.createNumericLiteral("1"),
|
178
|
-
),
|
179
|
-
],
|
180
|
-
),
|
181
|
-
),
|
182
|
-
],
|
183
|
-
true,
|
184
|
-
),
|
185
|
-
),
|
186
|
-
],
|
187
|
-
);
|
188
|
-
}
|
189
|
-
|
190
|
-
const pick = <T>(array: T[]): T => {
|
191
|
-
const rand: number = Math.random() * array.length;
|
192
|
-
const index: number = Math.min(array.length - 1, Math.floor(rand));
|
193
|
-
return array[index];
|
194
|
-
};
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
2
|
+
import ts from "typescript";
|
3
|
+
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
4
|
+
import { StatementFactory } from "typia/lib/factories/StatementFactory";
|
5
|
+
|
6
|
+
import { IHttpMigrateFile } from "../structures/IHttpMigrateFile";
|
7
|
+
import { IHttpMigrateProgram } from "../structures/IHttpMigrateProgram";
|
8
|
+
import { IHttpMigrateRoute } from "../structures/IHttpMigrateRoute";
|
9
|
+
import { FilePrinter } from "../utils/FilePrinter";
|
10
|
+
import { MigrateE2eFunctionProgrammer } from "./MigrateE2eFileProgrammer";
|
11
|
+
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
12
|
+
|
13
|
+
export namespace MigrateApiStartProgrammer {
|
14
|
+
export const write = (program: IHttpMigrateProgram): IHttpMigrateFile => {
|
15
|
+
const importer: MigrateImportProgrammer = new MigrateImportProgrammer();
|
16
|
+
const main: ts.VariableStatement = writeMain(program)(program.document)(
|
17
|
+
importer,
|
18
|
+
)(pick(program.routes));
|
19
|
+
const statements: ts.Statement[] = [
|
20
|
+
...importer.toStatements(
|
21
|
+
(name) => `@ORGANIZATION/PROJECT-api/lib/structures/${name}`,
|
22
|
+
),
|
23
|
+
FilePrinter.newLine(),
|
24
|
+
ts.factory.createImportDeclaration(
|
25
|
+
undefined,
|
26
|
+
ts.factory.createImportClause(
|
27
|
+
false,
|
28
|
+
undefined,
|
29
|
+
ts.factory.createNamedImports([
|
30
|
+
ts.factory.createImportSpecifier(
|
31
|
+
false,
|
32
|
+
undefined,
|
33
|
+
ts.factory.createIdentifier("TestGlobal"),
|
34
|
+
),
|
35
|
+
]),
|
36
|
+
),
|
37
|
+
ts.factory.createStringLiteral("./TestGlobal"),
|
38
|
+
undefined,
|
39
|
+
),
|
40
|
+
FilePrinter.newLine(),
|
41
|
+
main,
|
42
|
+
ts.factory.createExpressionStatement(writeStarter()),
|
43
|
+
];
|
44
|
+
return {
|
45
|
+
location: `test`,
|
46
|
+
file: "start.ts",
|
47
|
+
content: FilePrinter.write({ statements }),
|
48
|
+
};
|
49
|
+
};
|
50
|
+
|
51
|
+
const writeMain =
|
52
|
+
(config: IHttpMigrateProgram.IConfig) =>
|
53
|
+
(document: OpenApi.IDocument) =>
|
54
|
+
(importer: MigrateImportProgrammer) =>
|
55
|
+
(route: IHttpMigrateRoute): ts.VariableStatement =>
|
56
|
+
StatementFactory.constant({
|
57
|
+
name: "main",
|
58
|
+
value: ts.factory.createArrowFunction(
|
59
|
+
[ts.factory.createToken(ts.SyntaxKind.AsyncKeyword)],
|
60
|
+
undefined,
|
61
|
+
[],
|
62
|
+
undefined,
|
63
|
+
undefined,
|
64
|
+
ts.factory.createBlock(
|
65
|
+
[
|
66
|
+
writeConnection(config)(document)(importer),
|
67
|
+
...MigrateE2eFunctionProgrammer.writeBody(document.components)(
|
68
|
+
importer,
|
69
|
+
)(route),
|
70
|
+
],
|
71
|
+
true,
|
72
|
+
),
|
73
|
+
),
|
74
|
+
});
|
75
|
+
|
76
|
+
const writeConnection =
|
77
|
+
(config: IHttpMigrateProgram.IConfig) =>
|
78
|
+
(document: OpenApi.IDocument) =>
|
79
|
+
(importer: MigrateImportProgrammer): ts.VariableStatement =>
|
80
|
+
ts.factory.createVariableStatement(
|
81
|
+
undefined,
|
82
|
+
ts.factory.createVariableDeclarationList(
|
83
|
+
[
|
84
|
+
ts.factory.createVariableDeclaration(
|
85
|
+
"connection",
|
86
|
+
undefined,
|
87
|
+
ts.factory.createTypeReferenceNode(
|
88
|
+
ts.factory.createQualifiedName(
|
89
|
+
ts.factory.createIdentifier(
|
90
|
+
importer.external({
|
91
|
+
type: "default",
|
92
|
+
library: "@ORGANIZATION/PROJECT-api",
|
93
|
+
name: "api",
|
94
|
+
}),
|
95
|
+
),
|
96
|
+
ts.factory.createIdentifier("IConnection"),
|
97
|
+
),
|
98
|
+
),
|
99
|
+
ts.factory.createObjectLiteralExpression(
|
100
|
+
[
|
101
|
+
ts.factory.createSpreadAssignment(
|
102
|
+
ts.factory.createCallExpression(
|
103
|
+
ts.factory.createPropertyAccessExpression(
|
104
|
+
ts.factory.createIdentifier("TestGlobal"),
|
105
|
+
"connection",
|
106
|
+
),
|
107
|
+
undefined,
|
108
|
+
undefined,
|
109
|
+
),
|
110
|
+
),
|
111
|
+
...(document.servers?.[0]?.url?.length
|
112
|
+
? [
|
113
|
+
ts.factory.createPropertyAssignment(
|
114
|
+
"host",
|
115
|
+
ts.factory.createStringLiteral(
|
116
|
+
document.servers[0].url,
|
117
|
+
),
|
118
|
+
),
|
119
|
+
]
|
120
|
+
: []),
|
121
|
+
...(config.simulate === true
|
122
|
+
? [
|
123
|
+
ts.factory.createPropertyAssignment(
|
124
|
+
"simulate",
|
125
|
+
ts.factory.createTrue(),
|
126
|
+
),
|
127
|
+
]
|
128
|
+
: []),
|
129
|
+
],
|
130
|
+
true,
|
131
|
+
),
|
132
|
+
),
|
133
|
+
],
|
134
|
+
ts.NodeFlags.Const,
|
135
|
+
),
|
136
|
+
);
|
137
|
+
|
138
|
+
const writeStarter = (): ts.CallExpression =>
|
139
|
+
ts.factory.createCallExpression(
|
140
|
+
ts.factory.createPropertyAccessExpression(
|
141
|
+
ts.factory.createCallExpression(
|
142
|
+
ts.factory.createIdentifier("main"),
|
143
|
+
undefined,
|
144
|
+
undefined,
|
145
|
+
),
|
146
|
+
"catch",
|
147
|
+
),
|
148
|
+
undefined,
|
149
|
+
[
|
150
|
+
ts.factory.createArrowFunction(
|
151
|
+
undefined,
|
152
|
+
undefined,
|
153
|
+
[IdentifierFactory.parameter("exp")],
|
154
|
+
undefined,
|
155
|
+
undefined,
|
156
|
+
ts.factory.createBlock(
|
157
|
+
[
|
158
|
+
ts.factory.createExpressionStatement(
|
159
|
+
ts.factory.createCallExpression(
|
160
|
+
ts.factory.createPropertyAccessExpression(
|
161
|
+
ts.factory.createIdentifier("console"),
|
162
|
+
"log",
|
163
|
+
),
|
164
|
+
undefined,
|
165
|
+
[ts.factory.createIdentifier("exp")],
|
166
|
+
),
|
167
|
+
),
|
168
|
+
ts.factory.createExpressionStatement(
|
169
|
+
ts.factory.createCallExpression(
|
170
|
+
ts.factory.createPropertyAccessExpression(
|
171
|
+
ts.factory.createIdentifier("process"),
|
172
|
+
"exit",
|
173
|
+
),
|
174
|
+
undefined,
|
175
|
+
[
|
176
|
+
ts.factory.createPrefixMinus(
|
177
|
+
ts.factory.createNumericLiteral("1"),
|
178
|
+
),
|
179
|
+
],
|
180
|
+
),
|
181
|
+
),
|
182
|
+
],
|
183
|
+
true,
|
184
|
+
),
|
185
|
+
),
|
186
|
+
],
|
187
|
+
);
|
188
|
+
}
|
189
|
+
|
190
|
+
const pick = <T>(array: T[]): T => {
|
191
|
+
const rand: number = Math.random() * array.length;
|
192
|
+
const index: number = Math.min(array.length - 1, Math.floor(rand));
|
193
|
+
return array[index];
|
194
|
+
};
|
@@ -1,87 +1,87 @@
|
|
1
|
-
import { OpenApi } from "@samchon/openapi";
|
2
|
-
import { IPointer } from "tstl";
|
3
|
-
import ts from "typescript";
|
4
|
-
|
5
|
-
import { FilePrinter } from "../utils/FilePrinter";
|
6
|
-
import { MapUtil } from "../utils/MapUtil";
|
7
|
-
import { StringUtil } from "../utils/StringUtil";
|
8
|
-
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
9
|
-
import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
|
10
|
-
|
11
|
-
export namespace MigrateDtoProgrammer {
|
12
|
-
export interface IModule {
|
13
|
-
name: string;
|
14
|
-
children: Map<string, IModule>;
|
15
|
-
programmer:
|
16
|
-
| null
|
17
|
-
| ((importer: MigrateImportProgrammer) => ts.TypeAliasDeclaration);
|
18
|
-
}
|
19
|
-
|
20
|
-
export const compose = (
|
21
|
-
components: OpenApi.IComponents,
|
22
|
-
): Map<string, IModule> => {
|
23
|
-
const dict: Map<string, IModule> = new Map();
|
24
|
-
for (const [key, value] of Object.entries(components.schemas ?? {})) {
|
25
|
-
const emendedKey: string = key
|
26
|
-
.split("/")
|
27
|
-
.filter((str) => str.length !== 0)
|
28
|
-
.map(StringUtil.escapeNonVariable)
|
29
|
-
.join("");
|
30
|
-
prepare(dict)(emendedKey)((importer) =>
|
31
|
-
writeAlias(components)(importer)(emendedKey, value),
|
32
|
-
);
|
33
|
-
}
|
34
|
-
return dict;
|
35
|
-
};
|
36
|
-
|
37
|
-
const prepare =
|
38
|
-
(dict: Map<string, IModule>) =>
|
39
|
-
(name: string) =>
|
40
|
-
(
|
41
|
-
programmer: (
|
42
|
-
importer: MigrateImportProgrammer,
|
43
|
-
) => ts.TypeAliasDeclaration,
|
44
|
-
) => {
|
45
|
-
const accessors: string[] = name.split(".");
|
46
|
-
const modulo: IPointer<IModule> = { value: null! };
|
47
|
-
|
48
|
-
accessors.forEach((acc, i) => {
|
49
|
-
modulo.value = MapUtil.take(dict)(acc)(() => ({
|
50
|
-
name: acc,
|
51
|
-
children: new Map(),
|
52
|
-
programmer: null,
|
53
|
-
}));
|
54
|
-
if (i === accessors.length - 1) modulo.value.programmer = programmer;
|
55
|
-
dict = modulo.value.children;
|
56
|
-
});
|
57
|
-
return modulo!;
|
58
|
-
};
|
59
|
-
|
60
|
-
const writeAlias =
|
61
|
-
(components: OpenApi.IComponents) =>
|
62
|
-
(importer: MigrateImportProgrammer) =>
|
63
|
-
(key: string, value: OpenApi.IJsonSchema) =>
|
64
|
-
FilePrinter.description(
|
65
|
-
ts.factory.createTypeAliasDeclaration(
|
66
|
-
[ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
|
67
|
-
key.split(".").at(-1)!,
|
68
|
-
[],
|
69
|
-
MigrateSchemaProgrammer.write(components)(importer)(value),
|
70
|
-
),
|
71
|
-
writeComment(value),
|
72
|
-
);
|
73
|
-
}
|
74
|
-
|
75
|
-
const writeComment = (schema: OpenApi.IJsonSchema): string =>
|
76
|
-
[
|
77
|
-
...(schema.description?.length ? [schema.description] : []),
|
78
|
-
...(schema.description?.length &&
|
79
|
-
(schema.title !== undefined || schema.deprecated === true)
|
80
|
-
? [""]
|
81
|
-
: []),
|
82
|
-
...(schema.title !== undefined ? [`@title ${schema.title}`] : []),
|
83
|
-
...(schema.deprecated === true ? [`@deprecated`] : []),
|
84
|
-
]
|
85
|
-
.join("\n")
|
86
|
-
.split("*/")
|
87
|
-
.join("*\\/");
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
2
|
+
import { IPointer } from "tstl";
|
3
|
+
import ts from "typescript";
|
4
|
+
|
5
|
+
import { FilePrinter } from "../utils/FilePrinter";
|
6
|
+
import { MapUtil } from "../utils/MapUtil";
|
7
|
+
import { StringUtil } from "../utils/StringUtil";
|
8
|
+
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
9
|
+
import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
|
10
|
+
|
11
|
+
export namespace MigrateDtoProgrammer {
|
12
|
+
export interface IModule {
|
13
|
+
name: string;
|
14
|
+
children: Map<string, IModule>;
|
15
|
+
programmer:
|
16
|
+
| null
|
17
|
+
| ((importer: MigrateImportProgrammer) => ts.TypeAliasDeclaration);
|
18
|
+
}
|
19
|
+
|
20
|
+
export const compose = (
|
21
|
+
components: OpenApi.IComponents,
|
22
|
+
): Map<string, IModule> => {
|
23
|
+
const dict: Map<string, IModule> = new Map();
|
24
|
+
for (const [key, value] of Object.entries(components.schemas ?? {})) {
|
25
|
+
const emendedKey: string = key
|
26
|
+
.split("/")
|
27
|
+
.filter((str) => str.length !== 0)
|
28
|
+
.map(StringUtil.escapeNonVariable)
|
29
|
+
.join("");
|
30
|
+
prepare(dict)(emendedKey)((importer) =>
|
31
|
+
writeAlias(components)(importer)(emendedKey, value),
|
32
|
+
);
|
33
|
+
}
|
34
|
+
return dict;
|
35
|
+
};
|
36
|
+
|
37
|
+
const prepare =
|
38
|
+
(dict: Map<string, IModule>) =>
|
39
|
+
(name: string) =>
|
40
|
+
(
|
41
|
+
programmer: (
|
42
|
+
importer: MigrateImportProgrammer,
|
43
|
+
) => ts.TypeAliasDeclaration,
|
44
|
+
) => {
|
45
|
+
const accessors: string[] = name.split(".");
|
46
|
+
const modulo: IPointer<IModule> = { value: null! };
|
47
|
+
|
48
|
+
accessors.forEach((acc, i) => {
|
49
|
+
modulo.value = MapUtil.take(dict)(acc)(() => ({
|
50
|
+
name: acc,
|
51
|
+
children: new Map(),
|
52
|
+
programmer: null,
|
53
|
+
}));
|
54
|
+
if (i === accessors.length - 1) modulo.value.programmer = programmer;
|
55
|
+
dict = modulo.value.children;
|
56
|
+
});
|
57
|
+
return modulo!;
|
58
|
+
};
|
59
|
+
|
60
|
+
const writeAlias =
|
61
|
+
(components: OpenApi.IComponents) =>
|
62
|
+
(importer: MigrateImportProgrammer) =>
|
63
|
+
(key: string, value: OpenApi.IJsonSchema) =>
|
64
|
+
FilePrinter.description(
|
65
|
+
ts.factory.createTypeAliasDeclaration(
|
66
|
+
[ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
|
67
|
+
key.split(".").at(-1)!,
|
68
|
+
[],
|
69
|
+
MigrateSchemaProgrammer.write(components)(importer)(value),
|
70
|
+
),
|
71
|
+
writeComment(value),
|
72
|
+
);
|
73
|
+
}
|
74
|
+
|
75
|
+
const writeComment = (schema: OpenApi.IJsonSchema): string =>
|
76
|
+
[
|
77
|
+
...(schema.description?.length ? [schema.description] : []),
|
78
|
+
...(schema.description?.length &&
|
79
|
+
(schema.title !== undefined || schema.deprecated === true)
|
80
|
+
? [""]
|
81
|
+
: []),
|
82
|
+
...(schema.title !== undefined ? [`@title ${schema.title}`] : []),
|
83
|
+
...(schema.deprecated === true ? [`@deprecated`] : []),
|
84
|
+
]
|
85
|
+
.join("\n")
|
86
|
+
.split("*/")
|
87
|
+
.join("*\\/");
|