Skip to content

Commit

Permalink
Ignore wildcard URL case.
Browse files Browse the repository at this point in the history
When wildcase URL controller method exists, `@nestia/sdk` can't build it due to error from `path-to-regexp` library.

Therefore, decided to skip the wildcard controller method case.
  • Loading branch information
samchon committed Nov 6, 2023
1 parent 8338336 commit 6920f70
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 36 deletions.
9 changes: 5 additions & 4 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/sdk",
"version": "2.3.4",
"version": "2.3.5-dev.20231105-4",
"description": "Nestia SDK and Swagger generator",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -35,7 +35,7 @@
},
"homepage": "https://nestia.io",
"dependencies": {
"@nestia/fetcher": "^2.3.4",
"@nestia/fetcher": ">=2.3.4",
"cli": "^1.0.1",
"get-function-location": "^2.0.0",
"glob": "^7.2.0",
Expand All @@ -44,7 +44,7 @@
"tsconfck": "^2.0.1",
"tsconfig-paths": "^4.1.1",
"tstl": "^2.5.13",
"typia": "^5.2.4"
"typia": ">=5.2.4 <6.0.0"
},
"peerDependencies": {
"@nestia/fetcher": ">=2.3.4",
Expand All @@ -56,6 +56,7 @@
"typia": ">=5.2.4 <6.0.0"
},
"devDependencies": {
"@nestia/e2e": "^0.3.7",
"@nestjs/common": ">= 7.0.1",
"@nestjs/core": ">= 7.0.1",
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
Expand Down Expand Up @@ -85,4 +86,4 @@
"LICENSE",
"package.json"
]
}
}
75 changes: 46 additions & 29 deletions packages/sdk/src/NestiaSdkApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class NestiaSdkApplication {
await validate("sdk")(this.config.output);
await validate("e2e")(this.config.e2e);

title("Nestia E2E Generator");
print_title("Nestia E2E Generator");
await this.generate(
"e2e",
(config) => config,
Expand All @@ -69,7 +69,7 @@ export class NestiaSdkApplication {
"Error on NestiaApplication.sdk(): output directory does not exists.",
);

title("Nestia SDK Generator");
print_title("Nestia SDK Generator");
await this.generate("sdk", (config) => config, SdkGenerator.generate);
}

Expand All @@ -89,7 +89,7 @@ export class NestiaSdkApplication {
"Error on NestiaApplication.swagger(): output directory does not exists.",
);

title("Nestia Swagger Generator");
print_title("Nestia Swagger Generator");
await this.generate(
"swagger",
(config) => config.swagger!,
Expand All @@ -112,6 +112,7 @@ export class NestiaSdkApplication {
input: await ConfigAnalyzer.input(this.config),
checker: null!,
errors: [],
warnings: [],
};

console.log("Analyzing reflections");
Expand Down Expand Up @@ -170,9 +171,10 @@ export class NestiaSdkApplication {

// REPORT ERRORS
if (project.errors.length) {
report_errors(project.errors);
report_errors("error")(project.errors);
process.exit(-1);
}
if (project.warnings.length) report_errors("warning")(project.warnings);

// FIND IMPLICIT TYPES
const implicit: IRoute[] = routeList.filter(is_implicit_return_typed);
Expand All @@ -195,7 +197,7 @@ export class NestiaSdkApplication {
}
}

const title = (str: string): void => {
const print_title = (str: string): void => {
console.log("-----------------------------------------------------------");
console.log(` ${str}`);
console.log("-----------------------------------------------------------");
Expand All @@ -217,30 +219,45 @@ const is_implicit_return_typed = (route: IRoute): boolean => {
return true;
};

const report_errors = (errors: IErrorReport[]): void => {
// key: file
// key: controller
// key: function
// value: message
const map: Map<string, Map<string, Map<string, Set<string>>>> = new Map();
for (const e of errors) {
const file = MapUtil.take(map, e.file, () => new Map());
const controller = MapUtil.take(file, e.controller, () => new Map());
const func = MapUtil.take(controller, e.function, () => new Set());
func.add(e.message);
}
const report_errors =
(type: "error" | "warning") =>
(errors: IErrorReport[]): void => {
// key: file
// key: controller
// key: function
// value: message
const map: Map<
string,
Map<string, Map<string, Set<string>>>
> = new Map();
for (const e of errors) {
const file = MapUtil.take(map, e.file, () => new Map());
const controller = MapUtil.take(
file,
e.controller,
() => new Map(),
);
const func = MapUtil.take(controller, e.function, () => new Set());
func.add(e.message);
}

console.log("");
title("Nestia Error Report");
for (const [file, cMap] of map) {
for (const [controller, fMap] of cMap)
for (const [func, messages] of fMap) {
const location: string = path.relative(process.cwd(), file);
console.log(`${location} - error on ${controller}.${func}()`);
for (const msg of messages) console.log(` - ${msg}`);
console.log("");
}
}
};
console.log("");
print_title(`Nestia ${type[0].toUpperCase()}${type.slice(1)} Report`);
for (const [file, cMap] of map) {
for (const [controller, fMap] of cMap)
for (const [func, messages] of fMap) {
const location: string = path.relative(process.cwd(), file);
console.log(
`${location} - ${
func !== null
? `${controller}.${func}()`
: controller
}`,
);
for (const msg of messages) console.log(` - ${msg}`);
console.log("");
}
}
};

const VARIABLE = /[a-zA-Z_$0-9]/;
29 changes: 27 additions & 2 deletions packages/sdk/src/analyses/ReflectAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,19 @@ export namespace ReflectAnalyzer {
name,
functions: [],
prefixes,
paths: _Get_paths(creator),
paths: _Get_paths(creator).filter((str) => {
if (str.includes("*") === true) {
project.warnings.push({
file,
controller: name,
function: null,
message:
"@nestia/sdk does not compose wildcard controller.",
});
return false;
}
return true;
}),
versions: _Get_versions(creator),
security: _Get_securities(creator),
swaggerTgas:
Expand Down Expand Up @@ -251,7 +263,19 @@ export namespace ReflectAnalyzer {
const meta: IController.IFunction = {
name,
method: method === "ALL" ? "POST" : method,
paths: _Get_paths(proto),
paths: _Get_paths(proto).filter((str) => {
if (str.includes("*") === true) {
project.warnings.push({
file: controller.file,
controller: controller.name,
function: name,
message:
"@nestia/sdk does not compose wildcard method.",
});
return false;
}
return true;
}),
versions: _Get_versions(proto),
parameters,
status: Reflect.getMetadata(
Expand Down Expand Up @@ -291,6 +315,7 @@ export namespace ReflectAnalyzer {
controllerLocation,
metaLocation,
);
if (location.includes("*")) continue;

// LIST UP PARAMETERS
const binded: string[] = PathAnalyzer.parameters(
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/structures/IErrorReport.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface IErrorReport {
file: string;
controller: string;
function: string;
function: string | null;
message: string;
}
1 change: 1 addition & 0 deletions packages/sdk/src/structures/INestiaProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export interface INestiaProject {
input: INormalizedInput;
checker: ts.TypeChecker;
errors: IErrorReport[];
warnings: IErrorReport[];
}

0 comments on commit 6920f70

Please sign in to comment.