@nestia/sdk 2.4.3 → 2.4.4

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 (70) hide show
  1. package/lib/INestiaConfig.d.ts +13 -0
  2. package/lib/analyses/ControllerAnalyzer.js +12 -1
  3. package/lib/analyses/ControllerAnalyzer.js.map +1 -1
  4. package/lib/analyses/PathAnalyzer.d.ts +2 -2
  5. package/lib/analyses/PathAnalyzer.js +27 -11
  6. package/lib/analyses/PathAnalyzer.js.map +1 -1
  7. package/lib/analyses/ReflectAnalyzer.js +11 -2
  8. package/lib/analyses/ReflectAnalyzer.js.map +1 -1
  9. package/lib/executable/internal/NestiaConfigLoader.js +5 -1
  10. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  11. package/lib/executable/sdk.js +11 -11
  12. package/lib/generates/SwaggerGenerator.js +16 -22
  13. package/lib/generates/SwaggerGenerator.js.map +1 -1
  14. package/lib/generates/internal/SwaggerSchemaGenerator.js +22 -15
  15. package/lib/generates/internal/SwaggerSchemaGenerator.js.map +1 -1
  16. package/lib/structures/ISwaggerComponents.d.ts +1 -1
  17. package/lib/structures/ISwaggerRoute.d.ts +3 -3
  18. package/package.json +5 -5
  19. package/src/INestiaConfig.ts +248 -234
  20. package/src/NestiaSdkApplication.ts +253 -253
  21. package/src/analyses/AccessorAnalyzer.ts +60 -60
  22. package/src/analyses/ConfigAnalyzer.ts +147 -147
  23. package/src/analyses/ControllerAnalyzer.ts +390 -379
  24. package/src/analyses/ExceptionAnalyzer.ts +115 -115
  25. package/src/analyses/GenericAnalyzer.ts +51 -51
  26. package/src/analyses/ImportAnalyzer.ts +138 -138
  27. package/src/analyses/PathAnalyzer.ts +110 -98
  28. package/src/analyses/ReflectAnalyzer.ts +11 -6
  29. package/src/analyses/SecurityAnalyzer.ts +20 -20
  30. package/src/executable/internal/CommandParser.ts +15 -15
  31. package/src/executable/internal/NestiaConfigLoader.ts +67 -67
  32. package/src/executable/internal/NestiaSdkCommand.ts +60 -60
  33. package/src/executable/sdk.ts +73 -73
  34. package/src/generates/E2eGenerator.ts +64 -64
  35. package/src/generates/SdkGenerator.ts +96 -96
  36. package/src/generates/SwaggerGenerator.ts +376 -372
  37. package/src/generates/internal/E2eFileProgrammer.ts +123 -123
  38. package/src/generates/internal/SdkDistributionComposer.ts +91 -91
  39. package/src/generates/internal/SdkDtoGenerator.ts +424 -424
  40. package/src/generates/internal/SdkFileProgrammer.ts +106 -106
  41. package/src/generates/internal/SdkImportWizard.ts +55 -55
  42. package/src/generates/internal/SdkRouteDirectory.ts +17 -17
  43. package/src/generates/internal/SdkSimulationProgrammer.ts +133 -133
  44. package/src/generates/internal/SdkTypeDefiner.ts +119 -119
  45. package/src/generates/internal/SwaggerSchemaGenerator.ts +18 -2
  46. package/src/generates/internal/SwaggerSchemaValidator.ts +198 -198
  47. package/src/index.ts +4 -4
  48. package/src/module.ts +2 -2
  49. package/src/structures/IErrorReport.ts +6 -6
  50. package/src/structures/INestiaProject.ts +13 -13
  51. package/src/structures/INormalizedInput.ts +20 -20
  52. package/src/structures/ISwagger.ts +91 -91
  53. package/src/structures/ISwaggerComponents.ts +29 -29
  54. package/src/structures/ISwaggerError.ts +8 -8
  55. package/src/structures/ISwaggerInfo.ts +80 -80
  56. package/src/structures/ISwaggerLazyProperty.ts +7 -7
  57. package/src/structures/ISwaggerLazySchema.ts +7 -7
  58. package/src/structures/ISwaggerRoute.ts +51 -51
  59. package/src/structures/ISwaggerSecurityScheme.ts +65 -65
  60. package/src/structures/ITypeTuple.ts +6 -6
  61. package/src/structures/MethodType.ts +5 -5
  62. package/src/structures/ParamCategory.ts +1 -1
  63. package/src/structures/TypeEntry.ts +22 -22
  64. package/src/utils/ArrayUtil.ts +26 -26
  65. package/src/utils/FileRetriever.ts +22 -22
  66. package/src/utils/ImportDictionary.ts +125 -125
  67. package/src/utils/MapUtil.ts +14 -14
  68. package/src/utils/PathUtil.ts +10 -10
  69. package/src/utils/SourceFinder.ts +66 -66
  70. package/src/utils/StripEnums.ts +5 -5
@@ -1,379 +1,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 (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
- .map((path) => ({
278
- ...common,
279
- path: PathAnalyzer.escape(path, () => "ControllerAnalyzer.analyze()"),
280
- accessors: [...PathUtil.accessors(path), func.name],
281
- }));
282
- };
283
-
284
- const _Analyze_parameter =
285
- (project: INestiaProject) =>
286
- (
287
- genericDict: GenericAnalyzer.Dictionary,
288
- importDict: ImportAnalyzer.Dictionary,
289
- controller: IController,
290
- funcName: string,
291
- param: IController.IParameter,
292
- symbol: ts.Symbol,
293
- ): IRoute.IParameter | null => {
294
- const type: ts.Type = project.checker.getTypeOfSymbolAtLocation(
295
- symbol,
296
- symbol.valueDeclaration!,
297
- );
298
- const name: string = symbol.getEscapedName().toString();
299
-
300
- const optional: boolean = !!project.checker.symbolToParameterDeclaration(
301
- symbol,
302
- undefined,
303
- undefined,
304
- )?.questionToken;
305
-
306
- const errors: IErrorReport[] = [];
307
-
308
- // DO NOT SUPPORT BODY PARAMETER
309
- if (param.category === "body" && param.field !== undefined)
310
- errors.push({
311
- file: controller.file,
312
- controller: controller.name,
313
- function: funcName,
314
- message:
315
- `nestia does not support body field specification. ` +
316
- `Therefore, erase the "${name}" parameter and ` +
317
- `re-define a new body decorator accepting full structured message.`,
318
- });
319
- if (optional === true && param.category !== "query")
320
- errors.push({
321
- file: controller.file,
322
- controller: controller.name,
323
- function: funcName,
324
- message:
325
- `nestia does not support optional parameter except query parameter. ` +
326
- `Therefore, erase question mark on the "${name}" parameter, ` +
327
- `or re-define a new method without the "${name}" parameter.`,
328
- });
329
- if (
330
- optional === true &&
331
- param.category === "query" &&
332
- param.field === undefined
333
- )
334
- errors.push({
335
- file: controller.file,
336
- controller: controller.name,
337
- function: funcName,
338
- message:
339
- `nestia does not support optional query parameter without field specification. ` +
340
- `Therefore, erase question mark on the "${name}" parameter, ` +
341
- `or re-define re-define parameters for each query parameters.`,
342
- });
343
-
344
- // GET TYPE NAME
345
- const tuple: ITypeTuple | null = ImportAnalyzer.analyze(
346
- project.checker,
347
- genericDict,
348
- importDict,
349
- type,
350
- );
351
- if (tuple === null || tuple.typeName === "__type")
352
- errors.push({
353
- file: controller.file,
354
- controller: controller.name,
355
- function: funcName,
356
- message: `implicit (unnamed) parameter type from "${name}".`,
357
- });
358
- if (errors.length) {
359
- project.errors.push(...errors);
360
- return null;
361
- }
362
- return {
363
- ...param,
364
- name,
365
- optional,
366
- type: tuple!.type,
367
- typeName: tuple!.typeName,
368
- };
369
- };
370
-
371
- function _Analyze_versions(
372
- value:
373
- | Array<Exclude<VersionValue, Array<string | typeof VERSION_NEUTRAL>>>
374
- | undefined,
375
- ): Array<string | null> {
376
- if (value === undefined) return [null];
377
- return value.map((v) => (typeof v === "symbol" ? null : v));
378
- }
379
- }
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
+ }