@nestia/sdk 2.5.0-dev.20240130-7 → 2.5.0-dev.20240131

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 (63) hide show
  1. package/lib/NestiaSdkApplication.js +10 -8
  2. package/lib/NestiaSdkApplication.js.map +1 -1
  3. package/lib/analyses/ControllerAnalyzer.js +7 -2
  4. package/lib/analyses/ControllerAnalyzer.js.map +1 -1
  5. package/lib/analyses/ExceptionAnalyzer.js +3 -1
  6. package/lib/analyses/ExceptionAnalyzer.js.map +1 -1
  7. package/lib/executable/sdk.js +11 -11
  8. package/lib/generates/CloneGenerator.js +2 -0
  9. package/lib/generates/CloneGenerator.js.map +1 -1
  10. package/lib/generates/internal/E2eFileProgrammer.js +3 -1
  11. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  12. package/lib/generates/internal/SdkCloneProgrammer.js +4 -1
  13. package/lib/generates/internal/SdkCloneProgrammer.js.map +1 -1
  14. package/lib/generates/internal/SdkTypeProgrammer.js +4 -1
  15. package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -1
  16. package/package.json +3 -3
  17. package/src/NestiaSdkApplication.ts +15 -13
  18. package/src/analyses/AccessorAnalyzer.ts +60 -60
  19. package/src/analyses/ConfigAnalyzer.ts +147 -147
  20. package/src/analyses/ControllerAnalyzer.ts +399 -390
  21. package/src/analyses/ExceptionAnalyzer.ts +119 -115
  22. package/src/analyses/GenericAnalyzer.ts +51 -51
  23. package/src/analyses/ImportAnalyzer.ts +138 -138
  24. package/src/analyses/PathAnalyzer.ts +110 -110
  25. package/src/analyses/ReflectAnalyzer.ts +464 -464
  26. package/src/analyses/SecurityAnalyzer.ts +20 -20
  27. package/src/executable/internal/CommandParser.ts +15 -15
  28. package/src/executable/internal/NestiaConfigLoader.ts +67 -67
  29. package/src/executable/internal/NestiaSdkCommand.ts +60 -60
  30. package/src/executable/sdk.ts +73 -73
  31. package/src/generates/CloneGenerator.ts +1 -0
  32. package/src/generates/internal/E2eFileProgrammer.ts +5 -1
  33. package/src/generates/internal/SdkCloneProgrammer.ts +6 -1
  34. package/src/generates/internal/SdkDistributionComposer.ts +91 -91
  35. package/src/generates/internal/SdkImportWizard.ts +55 -55
  36. package/src/generates/internal/SdkRouteDirectory.ts +17 -17
  37. package/src/generates/internal/SdkTypeProgrammer.ts +6 -1
  38. package/src/generates/internal/SwaggerSchemaGenerator.ts +444 -444
  39. package/src/generates/internal/SwaggerSchemaValidator.ts +198 -198
  40. package/src/index.ts +4 -4
  41. package/src/module.ts +2 -2
  42. package/src/structures/IController.ts +91 -91
  43. package/src/structures/IErrorReport.ts +6 -6
  44. package/src/structures/INestiaProject.ts +13 -13
  45. package/src/structures/INormalizedInput.ts +20 -20
  46. package/src/structures/IRoute.ts +52 -52
  47. package/src/structures/ISwaggerComponents.ts +29 -29
  48. package/src/structures/ISwaggerError.ts +8 -8
  49. package/src/structures/ISwaggerInfo.ts +80 -80
  50. package/src/structures/ISwaggerLazyProperty.ts +7 -7
  51. package/src/structures/ISwaggerLazySchema.ts +7 -7
  52. package/src/structures/ISwaggerRoute.ts +51 -51
  53. package/src/structures/ISwaggerSecurityScheme.ts +65 -65
  54. package/src/structures/ITypeTuple.ts +6 -6
  55. package/src/structures/MethodType.ts +5 -5
  56. package/src/structures/ParamCategory.ts +1 -1
  57. package/src/structures/TypeEntry.ts +22 -22
  58. package/src/utils/ArrayUtil.ts +26 -26
  59. package/src/utils/FileRetriever.ts +22 -22
  60. package/src/utils/MapUtil.ts +14 -14
  61. package/src/utils/PathUtil.ts +10 -10
  62. package/src/utils/SourceFinder.ts +66 -66
  63. package/src/utils/StripEnums.ts +5 -5
@@ -1,390 +1,399 @@
1
- import { VERSION_NEUTRAL, VersionValue } from "@nestjs/common/interfaces";
2
- import path from "path";
3
- import { HashMap } from "tstl/container/HashMap";
4
- import ts from "typescript";
5
- import { CommentFactory } from "typia/lib/factories/CommentFactory";
6
-
7
- import { IController } from "../structures/IController";
8
- import { IErrorReport } from "../structures/IErrorReport";
9
- import { INestiaProject } from "../structures/INestiaProject";
10
- import { IRoute } from "../structures/IRoute";
11
- import { ITypeTuple } from "../structures/ITypeTuple";
12
- import { PathUtil } from "../utils/PathUtil";
13
- import { ExceptionAnalyzer } from "./ExceptionAnalyzer";
14
- import { GenericAnalyzer } from "./GenericAnalyzer";
15
- import { ImportAnalyzer } from "./ImportAnalyzer";
16
- import { PathAnalyzer } from "./PathAnalyzer";
17
- import { SecurityAnalyzer } from "./SecurityAnalyzer";
18
-
19
- export namespace ControllerAnalyzer {
20
- export const analyze =
21
- (project: INestiaProject) =>
22
- async (
23
- sourceFile: ts.SourceFile,
24
- controller: IController,
25
- ): Promise<IRoute[]> => {
26
- // FIND CONTROLLER CLASS
27
- const ret: IRoute[] = [];
28
- ts.forEachChild(sourceFile, (node) => {
29
- if (
30
- ts.isClassDeclaration(node) &&
31
- node.name?.escapedText === controller.name
32
- ) {
33
- // ANALYZE THE CONTROLLER
34
- ret.push(..._Analyze_controller(project)(controller, node));
35
- return;
36
- }
37
- });
38
- return ret;
39
- };
40
-
41
- /* ---------------------------------------------------------
42
- CLASS
43
- --------------------------------------------------------- */
44
- const _Analyze_controller =
45
- (project: INestiaProject) =>
46
- (controller: IController, classNode: ts.ClassDeclaration): IRoute[] => {
47
- const classType: ts.InterfaceType = project.checker.getTypeAtLocation(
48
- classNode,
49
- ) as ts.InterfaceType;
50
- const genericDict: GenericAnalyzer.Dictionary = GenericAnalyzer.analyze(
51
- project.checker,
52
- classNode,
53
- );
54
-
55
- const ret: IRoute[] = [];
56
- for (const property of classType.getProperties()) {
57
- // GET METHOD DECLARATION
58
- const declaration: ts.Declaration | undefined =
59
- (property.declarations || [])[0];
60
- if (!declaration || !ts.isMethodDeclaration(declaration)) continue;
61
-
62
- // IDENTIFIER MUST BE
63
- const identifier = declaration.name;
64
- if (!ts.isIdentifier(identifier)) continue;
65
-
66
- // ANALYZED WITH THE REFLECTED-FUNCTION
67
- const runtime: IController.IFunction | undefined =
68
- controller.functions.find((f) => f.name === identifier.escapedText);
69
- if (runtime === undefined) continue;
70
-
71
- const routes: IRoute[] = _Analyze_function(project)(
72
- controller,
73
- genericDict,
74
- runtime,
75
- declaration,
76
- property,
77
- );
78
- ret.push(...routes);
79
- }
80
- return ret;
81
- };
82
-
83
- /* ---------------------------------------------------------
84
- FUNCTION
85
- --------------------------------------------------------- */
86
- const _Analyze_function =
87
- (project: INestiaProject) =>
88
- (
89
- controller: IController,
90
- genericDict: GenericAnalyzer.Dictionary,
91
- func: IController.IFunction,
92
- declaration: ts.MethodDeclaration,
93
- symbol: ts.Symbol,
94
- ): IRoute[] => {
95
- // PREPARE ASSETS
96
- const type: ts.Type = project.checker.getTypeOfSymbolAtLocation(
97
- symbol,
98
- symbol.valueDeclaration!,
99
- );
100
- const signature: ts.Signature | undefined =
101
- project.checker.getSignaturesOfType(type, ts.SignatureKind.Call)[0];
102
- if (signature === undefined) {
103
- project.errors.push({
104
- file: controller.file,
105
- controller: controller.name,
106
- function: func.name,
107
- message: "unable to get the type signature.",
108
- });
109
- return [];
110
- }
111
-
112
- // SKIP @IGNORE TAG
113
- const jsDocTags = signature.getJsDocTags();
114
- if (jsDocTags.some((tag) => tag.name === "ignore")) return [];
115
-
116
- // EXPLORE CHILDREN TYPES
117
- const importDict: ImportAnalyzer.Dictionary = new HashMap();
118
- const parameters: Array<IRoute.IParameter | null> = func.parameters.map(
119
- (param) =>
120
- _Analyze_parameter(project)(
121
- genericDict,
122
- importDict,
123
- controller,
124
- func.name,
125
- param,
126
- signature.getParameters()[param.index],
127
- )!,
128
- );
129
- const outputType: ITypeTuple | null = ImportAnalyzer.analyze(
130
- project.checker,
131
- genericDict,
132
- importDict,
133
- signature.getReturnType(),
134
- );
135
- if (outputType === null || outputType.typeName === "__type") {
136
- project.errors.push({
137
- file: controller.file,
138
- controller: controller.name,
139
- function: func.name,
140
- message: "implicit (unnamed) return type.",
141
- });
142
- return [];
143
- } else if (
144
- func.method === "HEAD" &&
145
- outputType.typeName !== "void" &&
146
- outputType.typeName !== "undefined"
147
- ) {
148
- project.errors.push({
149
- file: controller.file,
150
- controller: controller.name,
151
- function: func.name,
152
- message: `HEAD method must return void type.`,
153
- });
154
- return [];
155
- }
156
-
157
- const exceptions = ExceptionAnalyzer.analyze(project)(
158
- genericDict,
159
- project.config.propagate === true ? importDict : new HashMap(),
160
- )(
161
- controller,
162
- func,
163
- )(declaration);
164
- const imports: [string, string[]][] = importDict
165
- .toJSON()
166
- .map((pair) => [pair.first, pair.second.toJSON()]);
167
-
168
- // CONSIDER SECURITY TAGS
169
- const security: Record<string, string[]>[] = SecurityAnalyzer.merge(
170
- ...controller.security,
171
- ...func.security,
172
- ...jsDocTags
173
- .filter((tag) => tag.name === "security")
174
- .map((tag) =>
175
- (tag.text ?? []).map((text) => {
176
- const line: string[] = text.text
177
- .split(" ")
178
- .filter((s) => s.trim())
179
- .filter((s) => !!s.length);
180
- if (line.length === 0) return {};
181
- return {
182
- [line[0]]: line.slice(1),
183
- };
184
- }),
185
- )
186
- .flat(),
187
- );
188
-
189
- // CONSTRUCT COMMON DATA
190
- const common: Omit<IRoute, "path" | "accessors"> = {
191
- ...func,
192
- parameters: parameters.filter((p) => p !== null) as IRoute.IParameter[],
193
- output: {
194
- type: outputType.type,
195
- typeName: outputType.typeName,
196
- contentType: func.contentType,
197
- },
198
- imports,
199
- status: func.status,
200
- symbol: {
201
- class: controller.name,
202
- function: func.name,
203
- },
204
- location: (() => {
205
- const file = declaration.getSourceFile();
206
- const { line, character } = file.getLineAndCharacterOfPosition(
207
- declaration.pos,
208
- );
209
- return `${path.relative(process.cwd(), file.fileName)}:${line + 1}:${
210
- character + 1
211
- }`;
212
- })(),
213
- description: CommentFactory.description(symbol),
214
- operationId: jsDocTags
215
- .find(({ name }) => name === "operationId")
216
- ?.text?.[0].text.split(" ")[0]
217
- .trim(),
218
- jsDocTags: jsDocTags,
219
- setHeaders: jsDocTags
220
- .filter(
221
- (t) =>
222
- t.text?.length &&
223
- t.text[0].text &&
224
- (t.name === "setHeader" || t.name === "assignHeaders"),
225
- )
226
- .map((t) =>
227
- t.name === "setHeader"
228
- ? {
229
- type: "setter",
230
- source: t.text![0].text.split(" ")[0].trim(),
231
- target: t.text![0].text.split(" ")[1]?.trim(),
232
- }
233
- : {
234
- type: "assigner",
235
- source: t.text![0].text,
236
- },
237
- ),
238
- security,
239
- exceptions,
240
- };
241
-
242
- // CONFIGURE PATHS
243
- const pathList: Set<string> = new Set();
244
- const versions: Array<string | null> = _Analyze_versions(
245
- project.input.versioning === undefined
246
- ? undefined
247
- : func.versions ??
248
- controller.versions ??
249
- (project.input.versioning?.defaultVersion !== undefined
250
- ? Array.isArray(project.input.versioning?.defaultVersion)
251
- ? project.input.versioning?.defaultVersion
252
- : [project.input.versioning?.defaultVersion]
253
- : undefined) ??
254
- undefined,
255
- );
256
- for (const prefix of controller.prefixes)
257
- for (const cPath of controller.paths)
258
- for (const filePath of func.paths)
259
- pathList.add(PathAnalyzer.join(prefix, cPath, filePath));
260
-
261
- return [...pathList]
262
- .map((individual) =>
263
- PathAnalyzer.combinate(project.input.globalPrefix)(
264
- [...versions].map((v) =>
265
- v === null
266
- ? null
267
- : project.input.versioning?.prefix?.length
268
- ? `${project.input.versioning.prefix}${v}`
269
- : v,
270
- ),
271
- )({
272
- method: func.method,
273
- path: individual,
274
- }),
275
- )
276
- .flat()
277
- .filter((path) => {
278
- const escaped: string | null = PathAnalyzer.escape(path);
279
- if (escaped === null)
280
- project.errors.push({
281
- file: controller.file,
282
- controller: controller.name,
283
- function: func.name,
284
- message: `unable to escape the path "${path}".`,
285
- });
286
- return escaped !== null;
287
- })
288
- .map((path) => ({
289
- ...common,
290
- path: PathAnalyzer.escape(path)!,
291
- accessors: [...PathUtil.accessors(path), func.name],
292
- }));
293
- };
294
-
295
- const _Analyze_parameter =
296
- (project: INestiaProject) =>
297
- (
298
- genericDict: GenericAnalyzer.Dictionary,
299
- importDict: ImportAnalyzer.Dictionary,
300
- controller: IController,
301
- funcName: string,
302
- param: IController.IParameter,
303
- symbol: ts.Symbol,
304
- ): IRoute.IParameter | null => {
305
- const type: ts.Type = project.checker.getTypeOfSymbolAtLocation(
306
- symbol,
307
- symbol.valueDeclaration!,
308
- );
309
- const name: string = symbol.getEscapedName().toString();
310
-
311
- const optional: boolean = !!project.checker.symbolToParameterDeclaration(
312
- symbol,
313
- undefined,
314
- undefined,
315
- )?.questionToken;
316
-
317
- const errors: IErrorReport[] = [];
318
-
319
- // DO NOT SUPPORT BODY PARAMETER
320
- if (param.category === "body" && param.field !== undefined)
321
- errors.push({
322
- file: controller.file,
323
- controller: controller.name,
324
- function: funcName,
325
- message:
326
- `nestia does not support body field specification. ` +
327
- `Therefore, erase the "${name}" parameter and ` +
328
- `re-define a new body decorator accepting full structured message.`,
329
- });
330
- if (optional === true && param.category !== "query")
331
- errors.push({
332
- file: controller.file,
333
- controller: controller.name,
334
- function: funcName,
335
- message:
336
- `nestia does not support optional parameter except query parameter. ` +
337
- `Therefore, erase question mark on the "${name}" parameter, ` +
338
- `or re-define a new method without the "${name}" parameter.`,
339
- });
340
- if (
341
- optional === true &&
342
- param.category === "query" &&
343
- param.field === undefined
344
- )
345
- errors.push({
346
- file: controller.file,
347
- controller: controller.name,
348
- function: funcName,
349
- message:
350
- `nestia does not support optional query parameter without field specification. ` +
351
- `Therefore, erase question mark on the "${name}" parameter, ` +
352
- `or re-define re-define parameters for each query parameters.`,
353
- });
354
-
355
- // GET TYPE NAME
356
- const tuple: ITypeTuple | null = ImportAnalyzer.analyze(
357
- project.checker,
358
- genericDict,
359
- importDict,
360
- type,
361
- );
362
- if (tuple === null || tuple.typeName === "__type")
363
- errors.push({
364
- file: controller.file,
365
- controller: controller.name,
366
- function: funcName,
367
- message: `implicit (unnamed) parameter type from "${name}".`,
368
- });
369
- if (errors.length) {
370
- project.errors.push(...errors);
371
- return null;
372
- }
373
- return {
374
- ...param,
375
- name,
376
- optional,
377
- type: tuple!.type,
378
- typeName: tuple!.typeName,
379
- };
380
- };
381
-
382
- function _Analyze_versions(
383
- value:
384
- | Array<Exclude<VersionValue, Array<string | typeof VERSION_NEUTRAL>>>
385
- | undefined,
386
- ): Array<string | null> {
387
- if (value === undefined) return [null];
388
- return value.map((v) => (typeof v === "symbol" ? null : v));
389
- }
390
- }
1
+ import { VERSION_NEUTRAL, VersionValue } from "@nestjs/common/interfaces";
2
+ import path from "path";
3
+ import { HashMap } from "tstl/container/HashMap";
4
+ import ts from "typescript";
5
+ import { CommentFactory } from "typia/lib/factories/CommentFactory";
6
+
7
+ import { IController } from "../structures/IController";
8
+ import { IErrorReport } from "../structures/IErrorReport";
9
+ import { INestiaProject } from "../structures/INestiaProject";
10
+ import { IRoute } from "../structures/IRoute";
11
+ import { ITypeTuple } from "../structures/ITypeTuple";
12
+ import { PathUtil } from "../utils/PathUtil";
13
+ import { ExceptionAnalyzer } from "./ExceptionAnalyzer";
14
+ import { GenericAnalyzer } from "./GenericAnalyzer";
15
+ import { ImportAnalyzer } from "./ImportAnalyzer";
16
+ import { PathAnalyzer } from "./PathAnalyzer";
17
+ import { SecurityAnalyzer } from "./SecurityAnalyzer";
18
+
19
+ export namespace ControllerAnalyzer {
20
+ export const analyze =
21
+ (project: INestiaProject) =>
22
+ async (
23
+ sourceFile: ts.SourceFile,
24
+ controller: IController,
25
+ ): Promise<IRoute[]> => {
26
+ // FIND CONTROLLER CLASS
27
+ const ret: IRoute[] = [];
28
+ ts.forEachChild(sourceFile, (node) => {
29
+ if (
30
+ ts.isClassDeclaration(node) &&
31
+ node.name?.escapedText === controller.name
32
+ ) {
33
+ // ANALYZE THE CONTROLLER
34
+ ret.push(..._Analyze_controller(project)(controller, node));
35
+ return;
36
+ }
37
+ });
38
+ return ret;
39
+ };
40
+
41
+ /* ---------------------------------------------------------
42
+ CLASS
43
+ --------------------------------------------------------- */
44
+ const _Analyze_controller =
45
+ (project: INestiaProject) =>
46
+ (controller: IController, classNode: ts.ClassDeclaration): IRoute[] => {
47
+ const classType: ts.InterfaceType = project.checker.getTypeAtLocation(
48
+ classNode,
49
+ ) as ts.InterfaceType;
50
+ const genericDict: GenericAnalyzer.Dictionary = GenericAnalyzer.analyze(
51
+ project.checker,
52
+ classNode,
53
+ );
54
+
55
+ const ret: IRoute[] = [];
56
+ for (const property of classType.getProperties()) {
57
+ // GET METHOD DECLARATION
58
+ const declaration: ts.Declaration | undefined =
59
+ (property.declarations || [])[0];
60
+ if (!declaration || !ts.isMethodDeclaration(declaration)) continue;
61
+
62
+ // IDENTIFIER MUST BE
63
+ const identifier = declaration.name;
64
+ if (!ts.isIdentifier(identifier)) continue;
65
+
66
+ // ANALYZED WITH THE REFLECTED-FUNCTION
67
+ const runtime: IController.IFunction | undefined =
68
+ controller.functions.find((f) => f.name === identifier.escapedText);
69
+ if (runtime === undefined) continue;
70
+
71
+ const routes: IRoute[] = _Analyze_function(project)(
72
+ controller,
73
+ genericDict,
74
+ runtime,
75
+ declaration,
76
+ property,
77
+ );
78
+ ret.push(...routes);
79
+ }
80
+ return ret;
81
+ };
82
+
83
+ /* ---------------------------------------------------------
84
+ FUNCTION
85
+ --------------------------------------------------------- */
86
+ const _Analyze_function =
87
+ (project: INestiaProject) =>
88
+ (
89
+ controller: IController,
90
+ genericDict: GenericAnalyzer.Dictionary,
91
+ func: IController.IFunction,
92
+ declaration: ts.MethodDeclaration,
93
+ symbol: ts.Symbol,
94
+ ): IRoute[] => {
95
+ // PREPARE ASSETS
96
+ const type: ts.Type = project.checker.getTypeOfSymbolAtLocation(
97
+ symbol,
98
+ symbol.valueDeclaration!,
99
+ );
100
+ const signature: ts.Signature | undefined =
101
+ project.checker.getSignaturesOfType(type, ts.SignatureKind.Call)[0];
102
+ if (signature === undefined) {
103
+ project.errors.push({
104
+ file: controller.file,
105
+ controller: controller.name,
106
+ function: func.name,
107
+ message: "unable to get the type signature.",
108
+ });
109
+ return [];
110
+ }
111
+
112
+ // SKIP @IGNORE TAG
113
+ const jsDocTags = signature.getJsDocTags();
114
+ if (jsDocTags.some((tag) => tag.name === "ignore")) return [];
115
+
116
+ // EXPLORE CHILDREN TYPES
117
+ const importDict: ImportAnalyzer.Dictionary = new HashMap();
118
+ const parameters: Array<IRoute.IParameter | null> = func.parameters.map(
119
+ (param) =>
120
+ _Analyze_parameter(project)(
121
+ genericDict,
122
+ importDict,
123
+ controller,
124
+ func.name,
125
+ param,
126
+ signature.getParameters()[param.index],
127
+ )!,
128
+ );
129
+ const outputType: ITypeTuple | null = ImportAnalyzer.analyze(
130
+ project.checker,
131
+ genericDict,
132
+ importDict,
133
+ signature.getReturnType(),
134
+ );
135
+ if (
136
+ outputType === null ||
137
+ (project.config.clone !== true &&
138
+ (outputType.typeName === "__type" ||
139
+ outputType.typeName === "__object"))
140
+ ) {
141
+ project.errors.push({
142
+ file: controller.file,
143
+ controller: controller.name,
144
+ function: func.name,
145
+ message: "implicit (unnamed) return type.",
146
+ });
147
+ return [];
148
+ } else if (
149
+ func.method === "HEAD" &&
150
+ outputType.typeName !== "void" &&
151
+ outputType.typeName !== "undefined"
152
+ ) {
153
+ project.errors.push({
154
+ file: controller.file,
155
+ controller: controller.name,
156
+ function: func.name,
157
+ message: `HEAD method must return void type.`,
158
+ });
159
+ return [];
160
+ }
161
+
162
+ const exceptions = ExceptionAnalyzer.analyze(project)(
163
+ genericDict,
164
+ project.config.propagate === true ? importDict : new HashMap(),
165
+ )(
166
+ controller,
167
+ func,
168
+ )(declaration);
169
+ const imports: [string, string[]][] = importDict
170
+ .toJSON()
171
+ .map((pair) => [pair.first, pair.second.toJSON()]);
172
+
173
+ // CONSIDER SECURITY TAGS
174
+ const security: Record<string, string[]>[] = SecurityAnalyzer.merge(
175
+ ...controller.security,
176
+ ...func.security,
177
+ ...jsDocTags
178
+ .filter((tag) => tag.name === "security")
179
+ .map((tag) =>
180
+ (tag.text ?? []).map((text) => {
181
+ const line: string[] = text.text
182
+ .split(" ")
183
+ .filter((s) => s.trim())
184
+ .filter((s) => !!s.length);
185
+ if (line.length === 0) return {};
186
+ return {
187
+ [line[0]]: line.slice(1),
188
+ };
189
+ }),
190
+ )
191
+ .flat(),
192
+ );
193
+
194
+ // CONSTRUCT COMMON DATA
195
+ const common: Omit<IRoute, "path" | "accessors"> = {
196
+ ...func,
197
+ parameters: parameters.filter((p) => p !== null) as IRoute.IParameter[],
198
+ output: {
199
+ type: outputType.type,
200
+ typeName: outputType.typeName,
201
+ contentType: func.contentType,
202
+ },
203
+ imports,
204
+ status: func.status,
205
+ symbol: {
206
+ class: controller.name,
207
+ function: func.name,
208
+ },
209
+ location: (() => {
210
+ const file = declaration.getSourceFile();
211
+ const { line, character } = file.getLineAndCharacterOfPosition(
212
+ declaration.pos,
213
+ );
214
+ return `${path.relative(process.cwd(), file.fileName)}:${line + 1}:${
215
+ character + 1
216
+ }`;
217
+ })(),
218
+ description: CommentFactory.description(symbol),
219
+ operationId: jsDocTags
220
+ .find(({ name }) => name === "operationId")
221
+ ?.text?.[0].text.split(" ")[0]
222
+ .trim(),
223
+ jsDocTags: jsDocTags,
224
+ setHeaders: jsDocTags
225
+ .filter(
226
+ (t) =>
227
+ t.text?.length &&
228
+ t.text[0].text &&
229
+ (t.name === "setHeader" || t.name === "assignHeaders"),
230
+ )
231
+ .map((t) =>
232
+ t.name === "setHeader"
233
+ ? {
234
+ type: "setter",
235
+ source: t.text![0].text.split(" ")[0].trim(),
236
+ target: t.text![0].text.split(" ")[1]?.trim(),
237
+ }
238
+ : {
239
+ type: "assigner",
240
+ source: t.text![0].text,
241
+ },
242
+ ),
243
+ security,
244
+ exceptions,
245
+ };
246
+
247
+ // CONFIGURE PATHS
248
+ const pathList: Set<string> = new Set();
249
+ const versions: Array<string | null> = _Analyze_versions(
250
+ project.input.versioning === undefined
251
+ ? undefined
252
+ : func.versions ??
253
+ controller.versions ??
254
+ (project.input.versioning?.defaultVersion !== undefined
255
+ ? Array.isArray(project.input.versioning?.defaultVersion)
256
+ ? project.input.versioning?.defaultVersion
257
+ : [project.input.versioning?.defaultVersion]
258
+ : undefined) ??
259
+ undefined,
260
+ );
261
+ for (const prefix of controller.prefixes)
262
+ for (const cPath of controller.paths)
263
+ for (const filePath of func.paths)
264
+ pathList.add(PathAnalyzer.join(prefix, cPath, filePath));
265
+
266
+ return [...pathList]
267
+ .map((individual) =>
268
+ PathAnalyzer.combinate(project.input.globalPrefix)(
269
+ [...versions].map((v) =>
270
+ v === null
271
+ ? null
272
+ : project.input.versioning?.prefix?.length
273
+ ? `${project.input.versioning.prefix}${v}`
274
+ : v,
275
+ ),
276
+ )({
277
+ method: func.method,
278
+ path: individual,
279
+ }),
280
+ )
281
+ .flat()
282
+ .filter((path) => {
283
+ const escaped: string | null = PathAnalyzer.escape(path);
284
+ if (escaped === null)
285
+ project.errors.push({
286
+ file: controller.file,
287
+ controller: controller.name,
288
+ function: func.name,
289
+ message: `unable to escape the path "${path}".`,
290
+ });
291
+ return escaped !== null;
292
+ })
293
+ .map((path) => ({
294
+ ...common,
295
+ path: PathAnalyzer.escape(path)!,
296
+ accessors: [...PathUtil.accessors(path), func.name],
297
+ }));
298
+ };
299
+
300
+ const _Analyze_parameter =
301
+ (project: INestiaProject) =>
302
+ (
303
+ genericDict: GenericAnalyzer.Dictionary,
304
+ importDict: ImportAnalyzer.Dictionary,
305
+ controller: IController,
306
+ funcName: string,
307
+ param: IController.IParameter,
308
+ symbol: ts.Symbol,
309
+ ): IRoute.IParameter | null => {
310
+ const type: ts.Type = project.checker.getTypeOfSymbolAtLocation(
311
+ symbol,
312
+ symbol.valueDeclaration!,
313
+ );
314
+ const name: string = symbol.getEscapedName().toString();
315
+
316
+ const optional: boolean = !!project.checker.symbolToParameterDeclaration(
317
+ symbol,
318
+ undefined,
319
+ undefined,
320
+ )?.questionToken;
321
+
322
+ const errors: IErrorReport[] = [];
323
+
324
+ // DO NOT SUPPORT BODY PARAMETER
325
+ if (param.category === "body" && param.field !== undefined)
326
+ errors.push({
327
+ file: controller.file,
328
+ controller: controller.name,
329
+ function: funcName,
330
+ message:
331
+ `nestia does not support body field specification. ` +
332
+ `Therefore, erase the "${name}" parameter and ` +
333
+ `re-define a new body decorator accepting full structured message.`,
334
+ });
335
+ if (optional === true && param.category !== "query")
336
+ errors.push({
337
+ file: controller.file,
338
+ controller: controller.name,
339
+ function: funcName,
340
+ message:
341
+ `nestia does not support optional parameter except query parameter. ` +
342
+ `Therefore, erase question mark on the "${name}" parameter, ` +
343
+ `or re-define a new method without the "${name}" parameter.`,
344
+ });
345
+ if (
346
+ optional === true &&
347
+ param.category === "query" &&
348
+ param.field === undefined
349
+ )
350
+ errors.push({
351
+ file: controller.file,
352
+ controller: controller.name,
353
+ function: funcName,
354
+ message:
355
+ `nestia does not support optional query parameter without field specification. ` +
356
+ `Therefore, erase question mark on the "${name}" parameter, ` +
357
+ `or re-define re-define parameters for each query parameters.`,
358
+ });
359
+
360
+ // GET TYPE NAME
361
+ const tuple: ITypeTuple | null = ImportAnalyzer.analyze(
362
+ project.checker,
363
+ genericDict,
364
+ importDict,
365
+ type,
366
+ );
367
+ if (
368
+ tuple === null ||
369
+ (project.config.clone !== true &&
370
+ (tuple.typeName === "__type" || tuple.typeName === "__object"))
371
+ )
372
+ errors.push({
373
+ file: controller.file,
374
+ controller: controller.name,
375
+ function: funcName,
376
+ message: `implicit (unnamed) parameter type from "${name}".`,
377
+ });
378
+ if (errors.length) {
379
+ project.errors.push(...errors);
380
+ return null;
381
+ }
382
+ return {
383
+ ...param,
384
+ name,
385
+ optional,
386
+ type: tuple!.type,
387
+ typeName: tuple!.typeName,
388
+ };
389
+ };
390
+
391
+ function _Analyze_versions(
392
+ value:
393
+ | Array<Exclude<VersionValue, Array<string | typeof VERSION_NEUTRAL>>>
394
+ | undefined,
395
+ ): Array<string | null> {
396
+ if (value === undefined) return [null];
397
+ return value.map((v) => (typeof v === "symbol" ? null : v));
398
+ }
399
+ }