@nestia/migrate 0.12.1 → 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 +5157 -948
- 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 +1 -1
- package/lib/factories/TypeLiteralFactory.js +3 -1
- package/lib/factories/TypeLiteralFactory.js.map +1 -1
- 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/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 +81 -44
- 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 +79 -78
- package/src/MigrateApplication.ts +8 -13
- package/src/analyzers/MigrateControllerAnalyzer.ts +7 -5
- package/src/analyzers/MigrateMethodAnalyzer.ts +103 -179
- package/src/bundles/NEST_TEMPLATE.ts +1 -1
- package/src/factories/TypeLiteralFactory.ts +8 -1
- 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 -117
- 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 +102 -54
- 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 -76
- 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 -1572
- 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 -91
- 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,3 +1,4 @@
|
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
1
2
|
import ts from "typescript";
|
2
3
|
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
3
4
|
import { StatementFactory } from "typia/lib/factories/StatementFactory";
|
@@ -5,7 +6,6 @@ import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
|
5
6
|
|
6
7
|
import { IMigrateController } from "../structures/IMigrateController";
|
7
8
|
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
8
|
-
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
9
9
|
import { MigrateApiFunctionProgrammer } from "./MigrateApiFunctionProgrammer";
|
10
10
|
import { MigrateApiNamespaceProgrammer } from "./MigrateApiNamespaceProgrammer";
|
11
11
|
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
@@ -18,7 +18,7 @@ export namespace MigrateApiSimulatationProgrammer {
|
|
18
18
|
alias: string;
|
19
19
|
}
|
20
20
|
export const random =
|
21
|
-
(components:
|
21
|
+
(components: OpenApi.IComponents) =>
|
22
22
|
(importer: MigrateImportProgrammer) =>
|
23
23
|
(props: IProps) => {
|
24
24
|
const output = props.route.success
|
@@ -70,7 +70,7 @@ export namespace MigrateApiSimulatationProgrammer {
|
|
70
70
|
};
|
71
71
|
|
72
72
|
export const simulate =
|
73
|
-
(components:
|
73
|
+
(components: OpenApi.IComponents) =>
|
74
74
|
(importer: MigrateImportProgrammer) =>
|
75
75
|
(props: IProps): ts.VariableStatement => {
|
76
76
|
const caller = () =>
|
@@ -121,7 +121,7 @@ export namespace MigrateApiSimulatationProgrammer {
|
|
121
121
|
};
|
122
122
|
|
123
123
|
const assert =
|
124
|
-
(components:
|
124
|
+
(components: OpenApi.IComponents) =>
|
125
125
|
(importer: MigrateImportProgrammer) =>
|
126
126
|
(props: IProps): ts.Statement[] => {
|
127
127
|
const parameters = [
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
1
2
|
import ts from "typescript";
|
2
3
|
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
3
4
|
import { StatementFactory } from "typia/lib/factories/StatementFactory";
|
@@ -5,7 +6,6 @@ import { StatementFactory } from "typia/lib/factories/StatementFactory";
|
|
5
6
|
import { IMigrateFile } from "../structures/IMigrateFile";
|
6
7
|
import { IMigrateProgram } from "../structures/IMigrateProgram";
|
7
8
|
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
8
|
-
import { ISwagger } from "../structures/ISwagger";
|
9
9
|
import { FilePrinter } from "../utils/FilePrinter";
|
10
10
|
import { MigrateE2eFunctionProgrammer } from "./MigrateE2eFileProgrammer";
|
11
11
|
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
@@ -13,7 +13,7 @@ import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
|
13
13
|
export namespace MigrateApiStartProgrammer {
|
14
14
|
export const write = (program: IMigrateProgram): IMigrateFile => {
|
15
15
|
const importer: MigrateImportProgrammer = new MigrateImportProgrammer();
|
16
|
-
const main: ts.VariableStatement = writeMain(program)(program.
|
16
|
+
const main: ts.VariableStatement = writeMain(program)(program.document)(
|
17
17
|
importer,
|
18
18
|
)(pick(program.controllers.map((c) => c.routes).flat()));
|
19
19
|
const statements: ts.Statement[] = [
|
@@ -50,7 +50,7 @@ export namespace MigrateApiStartProgrammer {
|
|
50
50
|
|
51
51
|
const writeMain =
|
52
52
|
(config: IMigrateProgram.IConfig) =>
|
53
|
-
(
|
53
|
+
(document: OpenApi.IDocument) =>
|
54
54
|
(importer: MigrateImportProgrammer) =>
|
55
55
|
(route: IMigrateRoute): ts.VariableStatement =>
|
56
56
|
StatementFactory.constant(
|
@@ -63,8 +63,8 @@ export namespace MigrateApiStartProgrammer {
|
|
63
63
|
undefined,
|
64
64
|
ts.factory.createBlock(
|
65
65
|
[
|
66
|
-
writeConnection(config)(
|
67
|
-
...MigrateE2eFunctionProgrammer.writeBody(
|
66
|
+
writeConnection(config)(document)(importer),
|
67
|
+
...MigrateE2eFunctionProgrammer.writeBody(document.components)(
|
68
68
|
importer,
|
69
69
|
)(route),
|
70
70
|
],
|
@@ -75,7 +75,7 @@ export namespace MigrateApiStartProgrammer {
|
|
75
75
|
|
76
76
|
const writeConnection =
|
77
77
|
(config: IMigrateProgram.IConfig) =>
|
78
|
-
(
|
78
|
+
(document: OpenApi.IDocument) =>
|
79
79
|
(importer: MigrateImportProgrammer): ts.VariableStatement =>
|
80
80
|
ts.factory.createVariableStatement(
|
81
81
|
undefined,
|
@@ -108,12 +108,12 @@ export namespace MigrateApiStartProgrammer {
|
|
108
108
|
undefined,
|
109
109
|
),
|
110
110
|
),
|
111
|
-
...(
|
111
|
+
...(document.servers?.[0]?.url?.length
|
112
112
|
? [
|
113
113
|
ts.factory.createPropertyAssignment(
|
114
114
|
"host",
|
115
115
|
ts.factory.createStringLiteral(
|
116
|
-
|
116
|
+
document.servers[0].url,
|
117
117
|
),
|
118
118
|
),
|
119
119
|
]
|
@@ -1,8 +1,7 @@
|
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
1
2
|
import { IPointer } from "tstl";
|
2
3
|
import ts from "typescript";
|
3
4
|
|
4
|
-
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
5
|
-
import { ISwaggerSchema } from "../structures/ISwaggerSchema";
|
6
5
|
import { FilePrinter } from "../utils/FilePrinter";
|
7
6
|
import { MapUtil } from "../utils/MapUtil";
|
8
7
|
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
@@ -18,7 +17,7 @@ export namespace MigrateDtoProgrammer {
|
|
18
17
|
}
|
19
18
|
|
20
19
|
export const compose = (
|
21
|
-
components:
|
20
|
+
components: OpenApi.IComponents,
|
22
21
|
): Map<string, IModule> => {
|
23
22
|
const dict: Map<string, IModule> = new Map();
|
24
23
|
for (const [key, value] of Object.entries(components.schemas ?? {}))
|
@@ -52,9 +51,9 @@ export namespace MigrateDtoProgrammer {
|
|
52
51
|
};
|
53
52
|
|
54
53
|
const writeAlias =
|
55
|
-
(components:
|
54
|
+
(components: OpenApi.IComponents) =>
|
56
55
|
(importer: MigrateImportProgrammer) =>
|
57
|
-
(key: string, value:
|
56
|
+
(key: string, value: OpenApi.IJsonSchema) =>
|
58
57
|
FilePrinter.description(
|
59
58
|
ts.factory.createTypeAliasDeclaration(
|
60
59
|
[ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
|
@@ -66,7 +65,7 @@ export namespace MigrateDtoProgrammer {
|
|
66
65
|
);
|
67
66
|
}
|
68
67
|
|
69
|
-
const writeComment = (schema:
|
68
|
+
const writeComment = (schema: OpenApi.IJsonSchema): string =>
|
70
69
|
[
|
71
70
|
...(schema.description?.length ? [schema.description] : []),
|
72
71
|
...(schema.description?.length &&
|
@@ -1,14 +1,14 @@
|
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
1
2
|
import ts from "typescript";
|
2
3
|
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
3
4
|
|
4
5
|
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
5
|
-
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
6
6
|
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
7
7
|
import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
|
8
8
|
|
9
9
|
export namespace MigrateE2eFunctionProgrammer {
|
10
10
|
export const write =
|
11
|
-
(components:
|
11
|
+
(components: OpenApi.IComponents) =>
|
12
12
|
(importer: MigrateImportProgrammer) =>
|
13
13
|
(route: IMigrateRoute): ts.FunctionDeclaration =>
|
14
14
|
ts.factory.createFunctionDeclaration(
|
@@ -41,7 +41,7 @@ export namespace MigrateE2eFunctionProgrammer {
|
|
41
41
|
);
|
42
42
|
|
43
43
|
export const writeBody =
|
44
|
-
(components:
|
44
|
+
(components: OpenApi.IComponents) =>
|
45
45
|
(importer: MigrateImportProgrammer) =>
|
46
46
|
(route: IMigrateRoute): ts.Statement[] => [
|
47
47
|
ts.factory.createVariableStatement(
|
@@ -83,7 +83,7 @@ export namespace MigrateE2eFunctionProgrammer {
|
|
83
83
|
];
|
84
84
|
|
85
85
|
const writeCallExpressionn =
|
86
|
-
(components:
|
86
|
+
(components: OpenApi.IComponents) =>
|
87
87
|
(importer: MigrateImportProgrammer) =>
|
88
88
|
(route: IMigrateRoute): ts.CallExpression =>
|
89
89
|
ts.factory.createCallExpression(
|
@@ -1,9 +1,9 @@
|
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
1
2
|
import ts from "typescript";
|
2
3
|
|
3
4
|
import { IMigrateFile } from "../structures/IMigrateFile";
|
4
5
|
import { IMigrateProgram } from "../structures/IMigrateProgram";
|
5
6
|
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
6
|
-
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
7
7
|
import { FilePrinter } from "../utils/FilePrinter";
|
8
8
|
import { MigrateE2eFunctionProgrammer } from "./MigrateE2eFileProgrammer";
|
9
9
|
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
@@ -11,11 +11,11 @@ import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
|
11
11
|
export namespace MigrateE2eProgrammer {
|
12
12
|
export const write = (program: IMigrateProgram): IMigrateFile[] =>
|
13
13
|
program.controllers
|
14
|
-
.map((c) => c.routes.map(writeFile(program.
|
14
|
+
.map((c) => c.routes.map(writeFile(program.document.components)))
|
15
15
|
.flat();
|
16
16
|
|
17
17
|
const writeFile =
|
18
|
-
(components:
|
18
|
+
(components: OpenApi.IComponents) =>
|
19
19
|
(route: IMigrateRoute): IMigrateFile => {
|
20
20
|
const importer: MigrateImportProgrammer = new MigrateImportProgrammer();
|
21
21
|
const func: ts.FunctionDeclaration =
|
@@ -1,117 +1,117 @@
|
|
1
|
-
import ts from "typescript";
|
2
|
-
|
3
|
-
import { TypeLiteralFactory } from "../factories/TypeLiteralFactory";
|
4
|
-
import { FilePrinter } from "../utils/FilePrinter";
|
5
|
-
import { MapUtil } from "../utils/MapUtil";
|
6
|
-
|
7
|
-
export class MigrateImportProgrammer {
|
8
|
-
private external_: Map<string, IClause> = new Map();
|
9
|
-
private dtos_: Set<string> = new Set();
|
10
|
-
|
11
|
-
public constructor() {}
|
12
|
-
|
13
|
-
public empty(): boolean {
|
14
|
-
return this.external_.size === 0 && this.dtos_.size === 0;
|
15
|
-
}
|
16
|
-
|
17
|
-
public external(props: MigrateImportProgrammer.IProps): string {
|
18
|
-
const clause: IClause = MapUtil.take(this.external_)(props.library)(() => ({
|
19
|
-
default: null,
|
20
|
-
instances: new Set(),
|
21
|
-
}));
|
22
|
-
const name: string = props.name.split(".")[0];
|
23
|
-
if (props.type === "default") clause.default = props.name;
|
24
|
-
else clause.instances.add(name);
|
25
|
-
return name;
|
26
|
-
}
|
27
|
-
|
28
|
-
public dto(name: string, namespace?: string): ts.TypeReferenceNode {
|
29
|
-
const file: string = name.split(".")[0];
|
30
|
-
this.dtos_.add(file);
|
31
|
-
return ts.factory.createTypeReferenceNode(
|
32
|
-
namespace?.length
|
33
|
-
? ts.factory.createQualifiedName(
|
34
|
-
ts.factory.createIdentifier(namespace),
|
35
|
-
ts.factory.createIdentifier(file),
|
36
|
-
)
|
37
|
-
: name,
|
38
|
-
);
|
39
|
-
}
|
40
|
-
|
41
|
-
public tag(type: string, arg: any): ts.TypeReferenceNode {
|
42
|
-
const instance: string = this.external({
|
43
|
-
type: "instance",
|
44
|
-
library: "typia",
|
45
|
-
name: "tags",
|
46
|
-
});
|
47
|
-
return ts.factory.createTypeReferenceNode(`${instance}.${type}`, [
|
48
|
-
TypeLiteralFactory.generate(arg),
|
49
|
-
]);
|
50
|
-
}
|
51
|
-
|
52
|
-
public toStatements(
|
53
|
-
dtoPath: (name: string) => string,
|
54
|
-
current?: string,
|
55
|
-
): ts.Statement[] {
|
56
|
-
return [
|
57
|
-
...[...this.external_.entries()].map(([library, props]) =>
|
58
|
-
ts.factory.createImportDeclaration(
|
59
|
-
undefined,
|
60
|
-
ts.factory.createImportClause(
|
61
|
-
false,
|
62
|
-
props.default !== null
|
63
|
-
? ts.factory.createIdentifier(props.default)
|
64
|
-
: undefined,
|
65
|
-
props.instances.size
|
66
|
-
? ts.factory.createNamedImports(
|
67
|
-
[...props.instances].map((i) =>
|
68
|
-
ts.factory.createImportSpecifier(
|
69
|
-
false,
|
70
|
-
undefined,
|
71
|
-
ts.factory.createIdentifier(i),
|
72
|
-
),
|
73
|
-
),
|
74
|
-
)
|
75
|
-
: undefined,
|
76
|
-
),
|
77
|
-
ts.factory.createStringLiteral(library),
|
78
|
-
),
|
79
|
-
),
|
80
|
-
...(this.external_.size && this.dtos_.size
|
81
|
-
? [FilePrinter.newLine()]
|
82
|
-
: []),
|
83
|
-
...[...this.dtos_]
|
84
|
-
.filter(
|
85
|
-
current ? (name) => name !== current!.split(".")[0] : () => true,
|
86
|
-
)
|
87
|
-
.map((i) =>
|
88
|
-
ts.factory.createImportDeclaration(
|
89
|
-
undefined,
|
90
|
-
ts.factory.createImportClause(
|
91
|
-
false,
|
92
|
-
undefined,
|
93
|
-
ts.factory.createNamedImports([
|
94
|
-
ts.factory.createImportSpecifier(
|
95
|
-
false,
|
96
|
-
undefined,
|
97
|
-
ts.factory.createIdentifier(i),
|
98
|
-
),
|
99
|
-
]),
|
100
|
-
),
|
101
|
-
ts.factory.createStringLiteral(dtoPath(i)),
|
102
|
-
),
|
103
|
-
),
|
104
|
-
];
|
105
|
-
}
|
106
|
-
}
|
107
|
-
export namespace MigrateImportProgrammer {
|
108
|
-
export interface IProps {
|
109
|
-
type: "default" | "instance";
|
110
|
-
library: string;
|
111
|
-
name: string;
|
112
|
-
}
|
113
|
-
}
|
114
|
-
interface IClause {
|
115
|
-
default: string | null;
|
116
|
-
instances: Set<string>;
|
117
|
-
}
|
1
|
+
import ts from "typescript";
|
2
|
+
|
3
|
+
import { TypeLiteralFactory } from "../factories/TypeLiteralFactory";
|
4
|
+
import { FilePrinter } from "../utils/FilePrinter";
|
5
|
+
import { MapUtil } from "../utils/MapUtil";
|
6
|
+
|
7
|
+
export class MigrateImportProgrammer {
|
8
|
+
private external_: Map<string, IClause> = new Map();
|
9
|
+
private dtos_: Set<string> = new Set();
|
10
|
+
|
11
|
+
public constructor() {}
|
12
|
+
|
13
|
+
public empty(): boolean {
|
14
|
+
return this.external_.size === 0 && this.dtos_.size === 0;
|
15
|
+
}
|
16
|
+
|
17
|
+
public external(props: MigrateImportProgrammer.IProps): string {
|
18
|
+
const clause: IClause = MapUtil.take(this.external_)(props.library)(() => ({
|
19
|
+
default: null,
|
20
|
+
instances: new Set(),
|
21
|
+
}));
|
22
|
+
const name: string = props.name.split(".")[0];
|
23
|
+
if (props.type === "default") clause.default = props.name;
|
24
|
+
else clause.instances.add(name);
|
25
|
+
return name;
|
26
|
+
}
|
27
|
+
|
28
|
+
public dto(name: string, namespace?: string): ts.TypeReferenceNode {
|
29
|
+
const file: string = name.split(".")[0];
|
30
|
+
this.dtos_.add(file);
|
31
|
+
return ts.factory.createTypeReferenceNode(
|
32
|
+
namespace?.length
|
33
|
+
? ts.factory.createQualifiedName(
|
34
|
+
ts.factory.createIdentifier(namespace),
|
35
|
+
ts.factory.createIdentifier(file),
|
36
|
+
)
|
37
|
+
: name,
|
38
|
+
);
|
39
|
+
}
|
40
|
+
|
41
|
+
public tag(type: string, arg: any): ts.TypeReferenceNode {
|
42
|
+
const instance: string = this.external({
|
43
|
+
type: "instance",
|
44
|
+
library: "typia",
|
45
|
+
name: "tags",
|
46
|
+
});
|
47
|
+
return ts.factory.createTypeReferenceNode(`${instance}.${type}`, [
|
48
|
+
TypeLiteralFactory.generate(arg),
|
49
|
+
]);
|
50
|
+
}
|
51
|
+
|
52
|
+
public toStatements(
|
53
|
+
dtoPath: (name: string) => string,
|
54
|
+
current?: string,
|
55
|
+
): ts.Statement[] {
|
56
|
+
return [
|
57
|
+
...[...this.external_.entries()].map(([library, props]) =>
|
58
|
+
ts.factory.createImportDeclaration(
|
59
|
+
undefined,
|
60
|
+
ts.factory.createImportClause(
|
61
|
+
false,
|
62
|
+
props.default !== null
|
63
|
+
? ts.factory.createIdentifier(props.default)
|
64
|
+
: undefined,
|
65
|
+
props.instances.size
|
66
|
+
? ts.factory.createNamedImports(
|
67
|
+
[...props.instances].map((i) =>
|
68
|
+
ts.factory.createImportSpecifier(
|
69
|
+
false,
|
70
|
+
undefined,
|
71
|
+
ts.factory.createIdentifier(i),
|
72
|
+
),
|
73
|
+
),
|
74
|
+
)
|
75
|
+
: undefined,
|
76
|
+
),
|
77
|
+
ts.factory.createStringLiteral(library),
|
78
|
+
),
|
79
|
+
),
|
80
|
+
...(this.external_.size && this.dtos_.size
|
81
|
+
? [FilePrinter.newLine()]
|
82
|
+
: []),
|
83
|
+
...[...this.dtos_]
|
84
|
+
.filter(
|
85
|
+
current ? (name) => name !== current!.split(".")[0] : () => true,
|
86
|
+
)
|
87
|
+
.map((i) =>
|
88
|
+
ts.factory.createImportDeclaration(
|
89
|
+
undefined,
|
90
|
+
ts.factory.createImportClause(
|
91
|
+
false,
|
92
|
+
undefined,
|
93
|
+
ts.factory.createNamedImports([
|
94
|
+
ts.factory.createImportSpecifier(
|
95
|
+
false,
|
96
|
+
undefined,
|
97
|
+
ts.factory.createIdentifier(i),
|
98
|
+
),
|
99
|
+
]),
|
100
|
+
),
|
101
|
+
ts.factory.createStringLiteral(dtoPath(i)),
|
102
|
+
),
|
103
|
+
),
|
104
|
+
];
|
105
|
+
}
|
106
|
+
}
|
107
|
+
export namespace MigrateImportProgrammer {
|
108
|
+
export interface IProps {
|
109
|
+
type: "default" | "instance";
|
110
|
+
library: string;
|
111
|
+
name: string;
|
112
|
+
}
|
113
|
+
}
|
114
|
+
interface IClause {
|
115
|
+
default: string | null;
|
116
|
+
instances: Set<string>;
|
117
|
+
}
|
@@ -1,7 +1,7 @@
|
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
1
2
|
import ts from "typescript";
|
2
3
|
|
3
4
|
import { IMigrateController } from "../structures/IMigrateController";
|
4
|
-
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
5
5
|
import { FilePrinter } from "../utils/FilePrinter";
|
6
6
|
import { StringUtil } from "../utils/StringUtil";
|
7
7
|
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
@@ -9,7 +9,7 @@ import { MigrateNestMethodProgrammer } from "./MigrateNestMethodProgrammer";
|
|
9
9
|
|
10
10
|
export namespace MigrateNestControllerProgrammer {
|
11
11
|
export const write =
|
12
|
-
(components:
|
12
|
+
(components: OpenApi.IComponents) =>
|
13
13
|
(controller: IMigrateController): ts.Statement[] => {
|
14
14
|
const importer: MigrateImportProgrammer = new MigrateImportProgrammer();
|
15
15
|
const $class = ts.factory.createClassDeclaration(
|
@@ -1,11 +1,10 @@
|
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
1
2
|
import ts from "typescript";
|
2
3
|
import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
|
3
4
|
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
4
5
|
import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
5
6
|
|
6
7
|
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
7
|
-
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
8
|
-
import { ISwaggerSchema } from "../structures/ISwaggerSchema";
|
9
8
|
import { FilePrinter } from "../utils/FilePrinter";
|
10
9
|
import { StringUtil } from "../utils/StringUtil";
|
11
10
|
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
@@ -13,7 +12,7 @@ import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
|
|
13
12
|
|
14
13
|
export namespace MigrateNestMethodProgrammer {
|
15
14
|
export const write =
|
16
|
-
(components:
|
15
|
+
(components: OpenApi.IComponents) =>
|
17
16
|
(importer: MigrateImportProgrammer) =>
|
18
17
|
(route: IMigrateRoute): ts.MethodDeclaration => {
|
19
18
|
const output: ts.TypeNode = route.success
|
@@ -75,7 +74,7 @@ export namespace MigrateNestMethodProgrammer {
|
|
75
74
|
].join("\n");
|
76
75
|
|
77
76
|
const writeMethodDecorators =
|
78
|
-
(components:
|
77
|
+
(components: OpenApi.IComponents) =>
|
79
78
|
(importer: MigrateImportProgrammer) =>
|
80
79
|
(route: IMigrateRoute): ts.Decorator[] => {
|
81
80
|
const external =
|
@@ -154,7 +153,7 @@ export namespace MigrateNestMethodProgrammer {
|
|
154
153
|
};
|
155
154
|
|
156
155
|
const writeParameters =
|
157
|
-
(components:
|
156
|
+
(components: OpenApi.IComponents) =>
|
158
157
|
(importer: MigrateImportProgrammer) =>
|
159
158
|
(route: IMigrateRoute): ts.ParameterDeclaration[] => [
|
160
159
|
...route.parameters.map(({ key, schema: value }) =>
|
@@ -216,9 +215,9 @@ export namespace MigrateNestMethodProgrammer {
|
|
216
215
|
|
217
216
|
const writeDtoParameter =
|
218
217
|
(accessor: { method: string | [string, string]; variable: string }) =>
|
219
|
-
(components:
|
218
|
+
(components: OpenApi.IComponents) =>
|
220
219
|
(importer: MigrateImportProgrammer) =>
|
221
|
-
(schema:
|
220
|
+
(schema: OpenApi.IJsonSchema): ts.ParameterDeclaration => {
|
222
221
|
const instance = ts.factory.createIdentifier(
|
223
222
|
importer.external({
|
224
223
|
type: "instance",
|
@@ -20,11 +20,11 @@ export namespace MigrateNestProgrammer {
|
|
20
20
|
location: c.location,
|
21
21
|
file: `${c.name}.ts`,
|
22
22
|
statements: MigrateNestControllerProgrammer.write(
|
23
|
-
program.
|
23
|
+
program.document.components,
|
24
24
|
)(c),
|
25
25
|
})),
|
26
26
|
...[
|
27
|
-
...MigrateDtoProgrammer.compose(program.
|
27
|
+
...MigrateDtoProgrammer.compose(program.document.components).entries(),
|
28
28
|
].map(([key, value]) => ({
|
29
29
|
location: "src/api/structures",
|
30
30
|
file: `${key}.ts`,
|