Skip to content

Commit 13d26a6

Browse files
Copilotsmorimoto
andauthored
Refactor parameter naming and remove TypeScript error suppressions (#1483)
* Initial plan * 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]> * Apply biome formatting fixes Co-authored-by: smorimoto <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: smorimoto <[email protected]>
1 parent 815f195 commit 13d26a6

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/schema-routes/schema-routes.ts

Lines changed: 12 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,9 @@ 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) || rawRoute;
9897

9998
// TODO forbid leading symbols [\]^` in a major release (allowed yet for backwards compatibility)
10099
const pathParamMatches = (routeName || "").match(
@@ -157,15 +156,16 @@ export class SchemaRoutes {
157156
);
158157

159158
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("-")) {
159+
if (typeof paramName === "string" && paramName.includes("-")) {
162160
consola.warn("wrong query param name", paramName);
163161
}
164162

165163
queryParams.push({
166164
$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),
165+
name:
166+
typeof paramName === "string"
167+
? lodash.camelCase(paramName)
168+
: lodash.camelCase(String(paramName)),
169169
required: true,
170170
type: "string",
171171
description: "",
@@ -178,7 +178,7 @@ export class SchemaRoutes {
178178
}
179179

180180
const result = {
181-
originalRoute: originalRouteName || "",
181+
originalRoute: rawRoute || "",
182182
route: fixedRoute,
183183
pathParams,
184184
queryParams,
@@ -416,8 +416,7 @@ export class SchemaRoutes {
416416
lodash.reduce(
417417
requestInfos,
418418
(acc, requestInfo, status) => {
419-
// @ts-expect-error TS(2554) FIXME: Expected 2 arguments, but got 1.
420-
const contentTypes = this.getContentTypes([requestInfo]);
419+
const contentTypes = this.getContentTypes([requestInfo], operationId);
421420

422421
return [
423422
...acc,

0 commit comments

Comments
 (0)