Skip to content

Commit 27a20ec

Browse files
Copilotsmorimoto
andcommitted
Refactor route parameter naming and fix TypeScript errors
- Rename routeInfoByMethodsMap to routesByMethod for clarity - Rename originalRouteName to rawRoute for better readability - Add type validation before paramName.includes() to prevent runtime errors - Add type validation before lodash.camelCase(paramName) to prevent runtime errors - Fix getContentTypes() call to pass required 2 arguments instead of 1 Co-authored-by: smorimoto <[email protected]>
1 parent ef1c921 commit 27a20ec

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/schema-routes/schema-routes.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ export class SchemaRoutes {
6565
]);
6666
}
6767

68-
createRequestsMap = (routeInfoByMethodsMap) => {
69-
const parameters = lodash.get(routeInfoByMethodsMap, "parameters");
68+
createRequestsMap = (routesByMethod) => {
69+
const parameters = lodash.get(routesByMethod, "parameters");
7070

7171
return lodash.reduce(
72-
routeInfoByMethodsMap,
72+
routesByMethod,
7373
(acc, requestInfo, method) => {
7474
if (
7575
method.startsWith("x-") ||
@@ -91,10 +91,10 @@ export class SchemaRoutes {
9191
);
9292
};
9393

94-
parseRouteName = (originalRouteName) => {
94+
parseRouteName = (rawRoute) => {
9595
const routeName =
96-
this.config.hooks.onPreBuildRoutePath(originalRouteName) ||
97-
originalRouteName;
96+
this.config.hooks.onPreBuildRoutePath(rawRoute) ||
97+
rawRoute;
9898

9999
// TODO forbid leading symbols [\]^` in a major release (allowed yet for backwards compatibility)
100100
const pathParamMatches = (routeName || "").match(
@@ -157,15 +157,13 @@ export class SchemaRoutes {
157157
);
158158

159159
for (const paramName of paramNames) {
160-
// @ts-expect-error TS(2339) FIXME: Property 'includes' does not exist on type 'unknow... Remove this comment to see the full error message
161-
if (paramName.includes("-")) {
160+
if (typeof paramName === "string" && paramName.includes("-")) {
162161
consola.warn("wrong query param name", paramName);
163162
}
164163

165164
queryParams.push({
166165
$match: paramName,
167-
// @ts-expect-error TS(2345) FIXME: Argument of type 'unknown' is not assignable to pa... Remove this comment to see the full error message
168-
name: lodash.camelCase(paramName),
166+
name: typeof paramName === "string" ? lodash.camelCase(paramName) : lodash.camelCase(String(paramName)),
169167
required: true,
170168
type: "string",
171169
description: "",
@@ -178,7 +176,7 @@ export class SchemaRoutes {
178176
}
179177

180178
const result = {
181-
originalRoute: originalRouteName || "",
179+
originalRoute: rawRoute || "",
182180
route: fixedRoute,
183181
pathParams,
184182
queryParams,
@@ -416,8 +414,7 @@ export class SchemaRoutes {
416414
lodash.reduce(
417415
requestInfos,
418416
(acc, requestInfo, status) => {
419-
// @ts-expect-error TS(2554) FIXME: Expected 2 arguments, but got 1.
420-
const contentTypes = this.getContentTypes([requestInfo]);
417+
const contentTypes = this.getContentTypes([requestInfo], operationId);
421418

422419
return [
423420
...acc,

0 commit comments

Comments
 (0)