@nestia/migrate 0.6.0 → 0.6.2

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.
Files changed (85) hide show
  1. package/lib/{NestiaMigrateApplication.d.ts → MigrateApplication.d.ts} +2 -2
  2. package/lib/{NestiaMigrateApplication.js → MigrateApplication.js} +54 -29
  3. package/lib/MigrateApplication.js.map +1 -0
  4. package/lib/analyzers/ControllerAnalyzer.d.ts +5 -0
  5. package/lib/{programmers/ControllerProgrammer.js → analyzers/ControllerAnalyzer.js} +19 -37
  6. package/lib/analyzers/ControllerAnalyzer.js.map +1 -0
  7. package/lib/analyzers/MethodAnalyzer.d.ts +9 -0
  8. package/lib/{programmers/RouteProgrammer.js → analyzers/MethodAnalyzer.js} +24 -112
  9. package/lib/analyzers/MethodAnalyzer.js.map +1 -0
  10. package/lib/analyzers/MigrateAnalyzer.d.ts +4 -0
  11. package/lib/analyzers/MigrateAnalyzer.js +12 -0
  12. package/lib/analyzers/MigrateAnalyzer.js.map +1 -0
  13. package/lib/archivers/FileArchiver.d.ts +3 -3
  14. package/lib/archivers/FileArchiver.js +16 -7
  15. package/lib/archivers/FileArchiver.js.map +1 -1
  16. package/lib/executable/migrate.js +18 -9
  17. package/lib/executable/migrate.js.map +1 -1
  18. package/lib/module.d.ts +1 -1
  19. package/lib/module.js +1 -1
  20. package/lib/module.js.map +1 -1
  21. package/lib/programmers/ApiFileProgrammer.d.ts +17 -0
  22. package/lib/programmers/ApiFileProgrammer.js +28 -0
  23. package/lib/programmers/ApiFileProgrammer.js.map +1 -0
  24. package/lib/programmers/ApiFunctionProgrammer.d.ts +13 -0
  25. package/lib/programmers/ApiFunctionProgrammer.js +85 -0
  26. package/lib/programmers/ApiFunctionProgrammer.js.map +1 -0
  27. package/lib/programmers/ApiNamespaceProgrammer.d.ts +13 -0
  28. package/lib/programmers/ApiNamespaceProgrammer.js +134 -0
  29. package/lib/programmers/ApiNamespaceProgrammer.js.map +1 -0
  30. package/lib/programmers/ApiProgrammer.d.ts +5 -0
  31. package/lib/programmers/ApiProgrammer.js +62 -0
  32. package/lib/programmers/ApiProgrammer.js.map +1 -0
  33. package/lib/programmers/DtoProgrammer.js +2 -2
  34. package/lib/programmers/DtoProgrammer.js.map +1 -1
  35. package/lib/programmers/ImportProgrammer.d.ts +2 -1
  36. package/lib/programmers/ImportProgrammer.js +19 -4
  37. package/lib/programmers/ImportProgrammer.js.map +1 -1
  38. package/lib/programmers/{ControllerProgrammer.d.ts → NestControllerProgrammer.d.ts} +1 -3
  39. package/lib/programmers/NestControllerProgrammer.js +31 -0
  40. package/lib/programmers/NestControllerProgrammer.js.map +1 -0
  41. package/lib/programmers/{RouteProgrammer.d.ts → NestMethodProgrammer.d.ts} +1 -7
  42. package/lib/programmers/NestMethodProgrammer.js +118 -0
  43. package/lib/programmers/NestMethodProgrammer.js.map +1 -0
  44. package/lib/programmers/{ModuleProgrammer.d.ts → NestModuleProgrammer.d.ts} +1 -1
  45. package/lib/programmers/{ModuleProgrammer.js → NestModuleProgrammer.js} +6 -6
  46. package/lib/programmers/NestModuleProgrammer.js.map +1 -0
  47. package/lib/programmers/{MigrateProgrammer.d.ts → NestProgrammer.d.ts} +1 -3
  48. package/lib/programmers/{MigrateProgrammer.js → NestProgrammer.js} +10 -14
  49. package/lib/programmers/NestProgrammer.js.map +1 -0
  50. package/lib/programmers/SchemaProgrammer.d.ts +1 -1
  51. package/lib/programmers/SchemaProgrammer.js +17 -17
  52. package/lib/programmers/SchemaProgrammer.js.map +1 -1
  53. package/lib/structures/IMigrateRoute.d.ts +13 -4
  54. package/lib/utils/SetupWizard.js +0 -3
  55. package/lib/utils/SetupWizard.js.map +1 -1
  56. package/lib/utils/StringUtil.d.ts +1 -0
  57. package/lib/utils/StringUtil.js +4 -2
  58. package/lib/utils/StringUtil.js.map +1 -1
  59. package/package.json +1 -1
  60. package/src/{NestiaMigrateApplication.ts → MigrateApplication.ts} +32 -22
  61. package/src/{programmers/ControllerProgrammer.ts → analyzers/ControllerAnalyzer.ts} +123 -155
  62. package/src/{programmers/RouteProgrammer.ts → analyzers/MethodAnalyzer.ts} +20 -218
  63. package/src/analyzers/MigrateAnalyzer.ts +9 -0
  64. package/src/archivers/FileArchiver.ts +10 -7
  65. package/src/executable/migrate.ts +8 -8
  66. package/src/module.ts +1 -1
  67. package/src/programmers/ApiFileProgrammer.ts +51 -0
  68. package/src/programmers/ApiFunctionProgrammer.ts +177 -0
  69. package/src/programmers/ApiNamespaceProgrammer.ts +395 -0
  70. package/src/programmers/ApiProgrammer.ts +68 -0
  71. package/src/programmers/DtoProgrammer.ts +3 -3
  72. package/src/programmers/ImportProgrammer.ts +37 -21
  73. package/src/programmers/NestControllerProgrammer.ts +48 -0
  74. package/src/programmers/NestMethodProgrammer.ts +228 -0
  75. package/src/programmers/{ModuleProgrammer.ts → NestModuleProgrammer.ts} +1 -1
  76. package/src/programmers/{MigrateProgrammer.ts → NestProgrammer.ts} +11 -12
  77. package/src/programmers/SchemaProgrammer.ts +22 -25
  78. package/src/structures/IMigrateRoute.ts +13 -5
  79. package/src/utils/SetupWizard.ts +0 -3
  80. package/src/utils/StringUtil.ts +11 -2
  81. package/lib/NestiaMigrateApplication.js.map +0 -1
  82. package/lib/programmers/ControllerProgrammer.js.map +0 -1
  83. package/lib/programmers/MigrateProgrammer.js.map +0 -1
  84. package/lib/programmers/ModuleProgrammer.js.map +0 -1
  85. package/lib/programmers/RouteProgrammer.js.map +0 -1
@@ -23,7 +23,7 @@ export namespace DtoProgrammer {
23
23
  const dict: Map<string, IModule> = new Map();
24
24
  for (const [key, value] of Object.entries(components.schemas ?? {}))
25
25
  prepare(dict)(key)((importer) =>
26
- writeAlias(importer)(components)(key, value),
26
+ writeAlias(components)(importer)(key, value),
27
27
  );
28
28
  return dict;
29
29
  };
@@ -48,15 +48,15 @@ export namespace DtoProgrammer {
48
48
  };
49
49
 
50
50
  const writeAlias =
51
- (importer: ImportProgrammer) =>
52
51
  (components: ISwaggerComponents) =>
52
+ (importer: ImportProgrammer) =>
53
53
  (key: string, value: ISwaggerSchema) =>
54
54
  FilePrinter.description(
55
55
  ts.factory.createTypeAliasDeclaration(
56
56
  [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
57
57
  key.split(".").at(-1)!,
58
58
  [],
59
- SchemaProgrammer.write(importer)(components)(value),
59
+ SchemaProgrammer.write(components)(importer)(value),
60
60
  ),
61
61
  writeComment(value),
62
62
  );
@@ -5,7 +5,13 @@ import { FilePrinter } from "../utils/FilePrinter";
5
5
  import { MapUtil } from "../utils/MapUtil";
6
6
 
7
7
  export class ImportProgrammer {
8
- private external_: Map<string, Set<string>> = new Map();
8
+ private external_: Map<
9
+ string,
10
+ {
11
+ default: string | null;
12
+ instances: Set<string>;
13
+ }
14
+ > = new Map();
9
15
  private dtos_: Set<string> = new Set();
10
16
 
11
17
  public constructor() {}
@@ -15,10 +21,14 @@ export class ImportProgrammer {
15
21
  }
16
22
 
17
23
  public external(props: ImportProgrammer.IProps): string {
18
- MapUtil.take(this.external_)(props.library)(() => new Set()).add(
19
- props.instance.split(".")[0],
20
- );
21
- return props.instance;
24
+ const element = MapUtil.take(this.external_)(props.library)(() => ({
25
+ default: null,
26
+ instances: new Set(),
27
+ }));
28
+ const name: string = props.name.split(".")[0];
29
+ if (props.type === "default") element.default = props.name;
30
+ else element.instances.add(name);
31
+ return name;
22
32
  }
23
33
 
24
34
  public dto(name: string): ts.TypeReferenceNode {
@@ -29,8 +39,9 @@ export class ImportProgrammer {
29
39
 
30
40
  public tag(type: string, arg: number | string): ts.TypeReferenceNode {
31
41
  this.external({
42
+ type: "instance",
32
43
  library: "typia",
33
- instance: "tags",
44
+ name: "tags",
34
45
  });
35
46
  return ts.factory.createTypeReferenceNode(`tags.${type}`, [
36
47
  ts.factory.createLiteralTypeNode(
@@ -46,25 +57,29 @@ export class ImportProgrammer {
46
57
  current?: string,
47
58
  ): ts.Statement[] {
48
59
  return [
49
- ...[...this.external_.entries()].map(([library, properties]) =>
50
- ts.factory.createImportDeclaration(
60
+ ...[...this.external_.entries()].map(([library, props]) => {
61
+ return ts.factory.createImportDeclaration(
51
62
  undefined,
52
63
  ts.factory.createImportClause(
53
64
  false,
54
- undefined,
55
- ts.factory.createNamedImports(
56
- [...properties].map((i) =>
57
- ts.factory.createImportSpecifier(
58
- false,
59
- undefined,
60
- ts.factory.createIdentifier(i),
61
- ),
62
- ),
63
- ),
65
+ props.default !== null
66
+ ? ts.factory.createIdentifier(props.default)
67
+ : undefined,
68
+ props.instances.size
69
+ ? ts.factory.createNamedImports(
70
+ [...props.instances].map((i) =>
71
+ ts.factory.createImportSpecifier(
72
+ false,
73
+ undefined,
74
+ ts.factory.createIdentifier(i),
75
+ ),
76
+ ),
77
+ )
78
+ : undefined,
64
79
  ),
65
80
  ts.factory.createStringLiteral(library),
66
- ),
67
- ),
81
+ );
82
+ }),
68
83
  ...(this.external_.size && this.dtos_.size ? [FilePrinter.enter()] : []),
69
84
  ...[...this.dtos_]
70
85
  .filter(
@@ -92,7 +107,8 @@ export class ImportProgrammer {
92
107
  }
93
108
  export namespace ImportProgrammer {
94
109
  export interface IProps {
110
+ type: "default" | "instance";
95
111
  library: string;
96
- instance: string;
112
+ name: string;
97
113
  }
98
114
  }
@@ -0,0 +1,48 @@
1
+ import ts from "typescript";
2
+
3
+ import { IMigrateController } from "../structures/IMigrateController";
4
+ import { ISwaggerComponents } from "../structures/ISwaggerComponents";
5
+ import { FilePrinter } from "../utils/FilePrinter";
6
+ import { StringUtil } from "../utils/StringUtil";
7
+ import { ImportProgrammer } from "./ImportProgrammer";
8
+ import { NestMethodProgrammer } from "./NestMethodProgrammer";
9
+
10
+ export namespace NestControllerProgrammer {
11
+ export const write =
12
+ (components: ISwaggerComponents) =>
13
+ (controller: IMigrateController): ts.Statement[] => {
14
+ const importer: ImportProgrammer = new ImportProgrammer();
15
+ const $class = ts.factory.createClassDeclaration(
16
+ [
17
+ ts.factory.createDecorator(
18
+ ts.factory.createCallExpression(
19
+ ts.factory.createIdentifier(
20
+ importer.external({
21
+ type: "instance",
22
+ library: "@nestjs/common",
23
+ name: "Controller",
24
+ }),
25
+ ),
26
+ [],
27
+ [ts.factory.createStringLiteral(controller.path)],
28
+ ),
29
+ ),
30
+ ts.factory.createToken(ts.SyntaxKind.ExportKeyword),
31
+ ],
32
+ controller.name,
33
+ [],
34
+ [],
35
+ controller.routes.map(NestMethodProgrammer.write(components)(importer)),
36
+ );
37
+ return [
38
+ ...importer.toStatements(
39
+ (ref) =>
40
+ `${"../".repeat(
41
+ StringUtil.splitWithNormalization(controller.location).length - 1,
42
+ )}api/structures/${ref}`,
43
+ ),
44
+ ...(importer.empty() ? [] : [FilePrinter.enter()]),
45
+ $class,
46
+ ];
47
+ };
48
+ }
@@ -0,0 +1,228 @@
1
+ import ts from "typescript";
2
+ import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
3
+ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
4
+ import { TypeFactory } from "typia/lib/factories/TypeFactory";
5
+
6
+ import { IMigrateRoute } from "../structures/IMigrateRoute";
7
+ import { ISwaggerSchema } from "../structures/ISwaggeSchema";
8
+ import { ISwaggerComponents } from "../structures/ISwaggerComponents";
9
+ import { FilePrinter } from "../utils/FilePrinter";
10
+ import { StringUtil } from "../utils/StringUtil";
11
+ import { ImportProgrammer } from "./ImportProgrammer";
12
+ import { SchemaProgrammer } from "./SchemaProgrammer";
13
+
14
+ export namespace NestMethodProgrammer {
15
+ export const write =
16
+ (components: ISwaggerComponents) =>
17
+ (importer: ImportProgrammer) =>
18
+ (route: IMigrateRoute): ts.MethodDeclaration => {
19
+ const output: ts.TypeNode = route.success
20
+ ? SchemaProgrammer.write(components)(importer)(route.success.schema)
21
+ : TypeFactory.keyword("void");
22
+
23
+ const method: ts.MethodDeclaration = ts.factory.createMethodDeclaration(
24
+ [
25
+ ...writeMethodDecorators(components)(importer)(route),
26
+ ts.factory.createToken(ts.SyntaxKind.PublicKeyword),
27
+ ts.factory.createToken(ts.SyntaxKind.AsyncKeyword),
28
+ ],
29
+ undefined,
30
+ route.name,
31
+ undefined,
32
+ undefined,
33
+ writeParameters(components)(importer)(route),
34
+ ts.factory.createTypeReferenceNode("Promise", [output]),
35
+ ts.factory.createBlock(
36
+ [
37
+ ...[
38
+ ...route.parameters.map((p) => StringUtil.normalize(p.key)),
39
+ ...(route.headers ? ["headers"] : []),
40
+ ...(route.query ? ["query"] : []),
41
+ ...(route.body ? ["body"] : []),
42
+ ].map((str) =>
43
+ ts.factory.createExpressionStatement(
44
+ ts.factory.createIdentifier(str),
45
+ ),
46
+ ),
47
+ ts.factory.createReturnStatement(
48
+ ts.factory.createCallExpression(
49
+ IdentifierFactory.access(
50
+ ts.factory.createIdentifier(
51
+ importer.external({
52
+ type: "default",
53
+ library: "typia",
54
+ name: "typia",
55
+ }),
56
+ ),
57
+ )("random"),
58
+ [output],
59
+ undefined,
60
+ ),
61
+ ),
62
+ ],
63
+ true,
64
+ ),
65
+ );
66
+ return FilePrinter.description(method, writeDescription(route));
67
+ };
68
+
69
+ const writeDescription = (method: IMigrateRoute): string =>
70
+ [
71
+ ...(method.description?.length ? [method.description.length, ""] : []),
72
+ ...(method.deprecated ? ["@deprecated"] : []),
73
+ ...method.tags.map((value) => `@tag ${value}`),
74
+ "@nestia Generated by Nestia - https://github.com/samchon/nestia",
75
+ ].join("\n");
76
+
77
+ const writeMethodDecorators =
78
+ (components: ISwaggerComponents) =>
79
+ (importer: ImportProgrammer) =>
80
+ (route: IMigrateRoute): ts.Decorator[] => {
81
+ const external =
82
+ (lib: string) =>
83
+ (instance: string): ts.Identifier =>
84
+ ts.factory.createIdentifier(
85
+ importer.external({
86
+ type: "instance",
87
+ library: lib,
88
+ name: instance,
89
+ }),
90
+ );
91
+ const router = (instance: string) =>
92
+ ts.factory.createDecorator(
93
+ ts.factory.createCallExpression(
94
+ IdentifierFactory.access(external("@nestia/core")(instance))(
95
+ StringUtil.capitalize(route.method),
96
+ ),
97
+ [],
98
+ [ts.factory.createStringLiteral(route.path)],
99
+ ),
100
+ );
101
+
102
+ const decorators: ts.Decorator[] = [];
103
+ if (route.success?.["x-nestia-encrypted"])
104
+ decorators.push(router("EncryptedRoute"));
105
+ else if (route.success?.type === "text/plain")
106
+ decorators.push(
107
+ ts.factory.createDecorator(
108
+ ts.factory.createCallExpression(
109
+ external("@nestjs/common")(StringUtil.capitalize(route.method)),
110
+ [],
111
+ [ts.factory.createStringLiteral(route.path)],
112
+ ),
113
+ ),
114
+ );
115
+ else if (route.success?.type === "application/x-www-form-urlencoded")
116
+ decorators.push(router("TypedQuery"));
117
+ else if (route.success?.type === "application/json")
118
+ decorators.push(router("TypedRoute"));
119
+ else if (route.method === "head")
120
+ decorators.push(
121
+ ts.factory.createDecorator(
122
+ ts.factory.createCallExpression(
123
+ external("@nestjs/common")("Head"),
124
+ [],
125
+ [ts.factory.createStringLiteral(route.path)],
126
+ ),
127
+ ),
128
+ );
129
+ for (const [key, value] of Object.entries(route.exceptions ?? {}))
130
+ decorators.push(
131
+ ts.factory.createDecorator(
132
+ ts.factory.createCallExpression(
133
+ external("@nestia/core")("TypedException"),
134
+ [SchemaProgrammer.write(components)(importer)(value.schema)],
135
+ [
136
+ isNaN(Number(key))
137
+ ? ts.factory.createStringLiteral(key)
138
+ : ExpressionFactory.number(Number(key)),
139
+ ...(value.description?.length
140
+ ? [ts.factory.createStringLiteral(value.description)]
141
+ : []),
142
+ ],
143
+ ),
144
+ ),
145
+ );
146
+ return decorators;
147
+ };
148
+
149
+ const writeParameters =
150
+ (components: ISwaggerComponents) =>
151
+ (importer: ImportProgrammer) =>
152
+ (route: IMigrateRoute): ts.ParameterDeclaration[] => [
153
+ ...route.parameters.map(({ key, schema: value }) =>
154
+ ts.factory.createParameterDeclaration(
155
+ [
156
+ ts.factory.createDecorator(
157
+ ts.factory.createCallExpression(
158
+ ts.factory.createIdentifier(
159
+ importer.external({
160
+ type: "instance",
161
+ library: "@nestia/core",
162
+ name: "TypedParam",
163
+ }),
164
+ ),
165
+ undefined,
166
+ [ts.factory.createStringLiteral(key)],
167
+ ),
168
+ ),
169
+ ],
170
+ undefined,
171
+ StringUtil.normalize(key),
172
+ undefined,
173
+ SchemaProgrammer.write(components)(importer)(value),
174
+ ),
175
+ ),
176
+ ...(route.headers
177
+ ? [
178
+ writeDtoParameter({ method: "TypedHeaders", variable: "headers" })(
179
+ components,
180
+ )(importer)(route.headers.schema),
181
+ ]
182
+ : []),
183
+ ...(route.query
184
+ ? [
185
+ writeDtoParameter({ method: "TypedQuery", variable: "query" })(
186
+ components,
187
+ )(importer)(route.query.schema),
188
+ ]
189
+ : []),
190
+ ...(route.body
191
+ ? [
192
+ writeDtoParameter({
193
+ method: route.body?.["x-nestia-encrypted"]
194
+ ? "EncryptedBody"
195
+ : "TypedBody",
196
+ variable: "body",
197
+ })(components)(importer)(route.body.schema),
198
+ ]
199
+ : []),
200
+ ];
201
+
202
+ const writeDtoParameter =
203
+ (accessor: { method: string; variable: string }) =>
204
+ (components: ISwaggerComponents) =>
205
+ (importer: ImportProgrammer) =>
206
+ (schema: ISwaggerSchema): ts.ParameterDeclaration =>
207
+ ts.factory.createParameterDeclaration(
208
+ [
209
+ ts.factory.createDecorator(
210
+ ts.factory.createCallExpression(
211
+ ts.factory.createIdentifier(
212
+ importer.external({
213
+ type: "instance",
214
+ library: "@nestia/core",
215
+ name: accessor.method,
216
+ }),
217
+ ),
218
+ undefined,
219
+ undefined,
220
+ ),
221
+ ),
222
+ ],
223
+ undefined,
224
+ StringUtil.normalize(accessor.variable),
225
+ undefined,
226
+ SchemaProgrammer.write(components)(importer)(schema),
227
+ );
228
+ }
@@ -3,7 +3,7 @@ import ts from "typescript";
3
3
  import { IMigrateController } from "../structures/IMigrateController";
4
4
  import { FilePrinter } from "../utils/FilePrinter";
5
5
 
6
- export namespace ModuleProgrammer {
6
+ export namespace NestModuleProgrammer {
7
7
  export const write = (controllers: IMigrateController[]): ts.Statement[] => [
8
8
  $import("@nestjs/common")("Module"),
9
9
  ...(controllers.length ? [FilePrinter.enter()] : []),
@@ -2,30 +2,26 @@ import ts from "typescript";
2
2
 
3
3
  import { IMigrateFile } from "../structures/IMigrateFile";
4
4
  import { IMigrateProgram } from "../structures/IMigrateProgram";
5
- import { ISwagger } from "../structures/ISwagger";
6
5
  import { FilePrinter } from "../utils/FilePrinter";
7
- import { ControllerProgrammer } from "./ControllerProgrammer";
8
6
  import { DtoProgrammer } from "./DtoProgrammer";
9
7
  import { ImportProgrammer } from "./ImportProgrammer";
10
- import { ModuleProgrammer } from "./ModuleProgrammer";
11
-
12
- export namespace MigrateProgrammer {
13
- export const analyze = (swagger: ISwagger): IMigrateProgram => ({
14
- swagger,
15
- controllers: ControllerProgrammer.analyze(swagger),
16
- });
8
+ import { NestControllerProgrammer } from "./NestControllerProgrammer";
9
+ import { NestModuleProgrammer } from "./NestModuleProgrammer";
17
10
 
11
+ export namespace NestProgrammer {
18
12
  export const write = (program: IMigrateProgram): IMigrateFile[] =>
19
13
  [
20
14
  {
21
15
  location: "src",
22
16
  file: "MyModule.ts",
23
- statements: ModuleProgrammer.write(program.controllers),
17
+ statements: NestModuleProgrammer.write(program.controllers),
24
18
  },
25
19
  ...program.controllers.map((c) => ({
26
20
  location: c.location,
27
21
  file: `${c.name}.ts`,
28
- statements: ControllerProgrammer.write(program.swagger.components)(c),
22
+ statements: NestControllerProgrammer.write(program.swagger.components)(
23
+ c,
24
+ ),
29
25
  })),
30
26
  ...[...DtoProgrammer.write(program.swagger.components).entries()].map(
31
27
  ([key, value]) => ({
@@ -40,7 +36,10 @@ export namespace MigrateProgrammer {
40
36
  content: FilePrinter.write({ statements: o.statements }),
41
37
  }));
42
38
 
43
- const writeDtoFile = (key: string, modulo: DtoProgrammer.IModule): ts.Statement[] => {
39
+ const writeDtoFile = (
40
+ key: string,
41
+ modulo: DtoProgrammer.IModule,
42
+ ): ts.Statement[] => {
44
43
  const importer = new ImportProgrammer();
45
44
  const statements: ts.Statement[] = iterate(importer)(modulo);
46
45
  if (statements.length === 0) return [];
@@ -15,8 +15,8 @@ export namespace SchemaProgrammer {
15
15
  FACADE
16
16
  ----------------------------------------------------------- */
17
17
  export const write =
18
- (importer: ImportProgrammer) =>
19
18
  (components: ISwaggerComponents) =>
19
+ (importer: ImportProgrammer) =>
20
20
  (schema: ISwaggerSchema): ts.TypeNode => {
21
21
  const union: ts.TypeNode[] = [];
22
22
  if (SwaggerTypeChecker.isUnknown(schema))
@@ -36,16 +36,16 @@ export namespace SchemaProgrammer {
36
36
  else if (SwaggerTypeChecker.isString(schema))
37
37
  return writeString(importer)(schema);
38
38
  else if (SwaggerTypeChecker.isArray(schema))
39
- return writeArray(importer)(components)(schema);
39
+ return writeArray(components)(importer)(schema);
40
40
  else if (SwaggerTypeChecker.isObject(schema))
41
- return writeObject(importer)(components)(schema);
41
+ return writeObject(components)(importer)(schema);
42
42
  else if (SwaggerTypeChecker.isReference(schema))
43
43
  return writeReference(importer)(schema);
44
44
  // NESTED UNION
45
45
  else if (SwaggerTypeChecker.isAnyOf(schema))
46
- return writeUnion(importer)(components)(schema.anyOf);
46
+ return writeUnion(components)(importer)(schema.anyOf);
47
47
  else if (SwaggerTypeChecker.isOneOf(schema))
48
- return writeUnion(importer)(components)(schema.oneOf);
48
+ return writeUnion(components)(importer)(schema.oneOf);
49
49
  else return TypeFactory.keyword("any");
50
50
  })();
51
51
  union.push(type);
@@ -141,12 +141,12 @@ export namespace SchemaProgrammer {
141
141
  INSTANCES
142
142
  ----------------------------------------------------------- */
143
143
  const writeArray =
144
- (importer: ImportProgrammer) =>
145
144
  (components: ISwaggerComponents) =>
145
+ (importer: ImportProgrammer) =>
146
146
  (schema: ISwaggerSchema.IArray): ts.TypeNode => {
147
147
  const intersection: ts.TypeNode[] = [
148
148
  ts.factory.createArrayTypeNode(
149
- write(importer)(components)(schema.items),
149
+ write(components)(importer)(schema.items),
150
150
  ),
151
151
  ];
152
152
  if (schema.minItems !== undefined)
@@ -159,13 +159,13 @@ export namespace SchemaProgrammer {
159
159
  };
160
160
 
161
161
  const writeObject =
162
- (importer: ImportProgrammer) =>
163
162
  (components: ISwaggerComponents) =>
163
+ (importer: ImportProgrammer) =>
164
164
  (schema: ISwaggerSchema.IObject): ts.TypeNode => {
165
165
  const regular = () =>
166
166
  ts.factory.createTypeLiteralNode(
167
167
  Object.entries(schema.properties ?? []).map(([key, value]) =>
168
- writeRegularProperty(importer)(components)(schema.required ?? [])(
168
+ writeRegularProperty(components)(importer)(schema.required ?? [])(
169
169
  key,
170
170
  value,
171
171
  ),
@@ -173,24 +173,21 @@ export namespace SchemaProgrammer {
173
173
  );
174
174
  const dynamic = () =>
175
175
  ts.factory.createTypeLiteralNode([
176
- writeDynamicProperty(importer)(components)(
176
+ writeDynamicProperty(components)(importer)(
177
177
  schema.additionalProperties as ISwaggerSchema,
178
178
  ),
179
179
  ]);
180
- return FilePrinter.description(
181
- !!schema.properties?.length &&
182
- typeof schema.additionalProperties === "object"
183
- ? ts.factory.createIntersectionTypeNode([regular(), dynamic()])
184
- : typeof schema.additionalProperties === "object"
185
- ? dynamic()
186
- : regular(),
187
- writeComment(schema),
188
- );
180
+ return !!schema.properties?.length &&
181
+ typeof schema.additionalProperties === "object"
182
+ ? ts.factory.createIntersectionTypeNode([regular(), dynamic()])
183
+ : typeof schema.additionalProperties === "object"
184
+ ? dynamic()
185
+ : regular();
189
186
  };
190
187
 
191
188
  const writeRegularProperty =
192
- (importer: ImportProgrammer) =>
193
189
  (components: ISwaggerComponents) =>
190
+ (importer: ImportProgrammer) =>
194
191
  (required: string[]) =>
195
192
  (key: string, value: ISwaggerSchema) =>
196
193
  FilePrinter.description(
@@ -202,14 +199,14 @@ export namespace SchemaProgrammer {
202
199
  required.includes(key)
203
200
  ? undefined
204
201
  : ts.factory.createToken(ts.SyntaxKind.QuestionToken),
205
- write(importer)(components)(value),
202
+ write(components)(importer)(value),
206
203
  ),
207
204
  writeComment(value),
208
205
  );
209
206
 
210
207
  const writeDynamicProperty =
211
- (importer: ImportProgrammer) =>
212
208
  (components: ISwaggerComponents) =>
209
+ (importer: ImportProgrammer) =>
213
210
  (value: ISwaggerSchema) =>
214
211
  FilePrinter.description(
215
212
  ts.factory.createIndexSignature(
@@ -223,7 +220,7 @@ export namespace SchemaProgrammer {
223
220
  TypeFactory.keyword("string"),
224
221
  ),
225
222
  ],
226
- write(importer)(components)(value),
223
+ write(components)(importer)(value),
227
224
  ),
228
225
  writeComment(value),
229
226
  );
@@ -237,10 +234,10 @@ export namespace SchemaProgrammer {
237
234
  UNIONS
238
235
  ----------------------------------------------------------- */
239
236
  const writeUnion =
240
- (importer: ImportProgrammer) =>
241
237
  (components: ISwaggerComponents) =>
238
+ (importer: ImportProgrammer) =>
242
239
  (elements: ISwaggerSchema[]): ts.UnionTypeNode =>
243
- ts.factory.createUnionTypeNode(elements.map(write(importer)(components)));
240
+ ts.factory.createUnionTypeNode(elements.map(write(components)(importer)));
244
241
  }
245
242
  const createNode = (text: string) => ts.factory.createTypeReferenceNode(text);
246
243
  const writeComment = (schema: ISwaggerSchema): string =>
@@ -1,5 +1,3 @@
1
- import { IJsDocTagInfo } from "typia/lib/schemas/metadata/IJsDocTagInfo";
2
-
3
1
  import { ISwaggerSchema } from "./ISwaggeSchema";
4
2
 
5
3
  export interface IMigrateRoute {
@@ -7,13 +5,14 @@ export interface IMigrateRoute {
7
5
  path: string;
8
6
  method: string;
9
7
  parameters: IMigrateRoute.IParameter[];
10
- headers: ISwaggerSchema | null;
11
- query: ISwaggerSchema | null;
8
+ headers: IMigrateRoute.IHeaders | null;
9
+ query: IMigrateRoute.IQuery | null;
12
10
  body: IMigrateRoute.IBody | null;
13
11
  success: IMigrateRoute.IBody | null;
14
12
  exceptions: Record<string, IMigrateRoute.IException>;
15
13
  description?: string;
16
- "x-nestia-jsDocTags"?: IJsDocTagInfo[];
14
+ tags: string[];
15
+ deprecated: boolean;
17
16
  }
18
17
  export namespace IMigrateRoute {
19
18
  export interface IParameter {
@@ -21,7 +20,16 @@ export namespace IMigrateRoute {
21
20
  schema: ISwaggerSchema;
22
21
  description?: string;
23
22
  }
23
+ export interface IHeaders {
24
+ key: string;
25
+ schema: ISwaggerSchema;
26
+ }
27
+ export interface IQuery {
28
+ key: string;
29
+ schema: ISwaggerSchema;
30
+ }
24
31
  export interface IBody {
32
+ key: string;
25
33
  type:
26
34
  | "text/plain"
27
35
  | "application/json"
@@ -3,9 +3,6 @@ import cp from "child_process";
3
3
  export namespace SetupWizard {
4
4
  export const setup = (output: string) => {
5
5
  execute(output)("npm install");
6
- execute(output)("npx nestia e2e", "npm run build:sdk");
7
- execute(output)("npm run build:test");
8
- execute(output)("npm run test");
9
6
  };
10
7
 
11
8
  const execute = (cwd: string) => (command: string, fake?: string) => {
@@ -1,3 +1,5 @@
1
+ import { NamingConvention } from "typia/lib/utils/NamingConvention";
2
+
1
3
  export namespace StringUtil {
2
4
  export const capitalize = (str: string) =>
3
5
  str[0].toUpperCase() + str.slice(1).toLowerCase();
@@ -5,12 +7,14 @@ export namespace StringUtil {
5
7
  export const pascal = (path: string) =>
6
8
  splitWithNormalization(path)
7
9
  .filter((str) => str[0] !== "{")
8
- .map(capitalize)
10
+ .map(NamingConvention.pascal)
9
11
  .join("");
10
12
 
11
13
  export const camel = (path: string) =>
12
14
  splitWithNormalization(path)
13
- .map((str, i) => (i === 0 ? str : capitalize(str)))
15
+ .map((str, i) =>
16
+ i === 0 ? NamingConvention.camel(str) : NamingConvention.pascal(str),
17
+ )
14
18
  .join("");
15
19
 
16
20
  export const splitWithNormalization = (path: string) =>
@@ -48,4 +52,9 @@ export namespace StringUtil {
48
52
  .filter((str) => str[0] !== "{" || str[str.length - 1] === "}")
49
53
  .join("/");
50
54
  };
55
+
56
+ export const escapeDuplicate =
57
+ (keep: string[]) =>
58
+ (change: string): string =>
59
+ keep.includes(change) ? escapeDuplicate(keep)(`_${change}`) : change;
51
60
  }