Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 30, 2025

All Changes Applied Successfully

This PR applies code quality improvements to src/schema-routes/schema-routes.ts:

Parameter Naming Improvements:

  • Renamed routeInfoByMethodsMaproutesByMethod for better clarity (lines 68-72)
  • Renamed originalRouteNamerawRoute for better readability (lines 94-97, 179)

TypeScript Error Fixes:

  • Added string type validation before paramName.includes() to prevent runtime errors (line 160)
  • Added string type validation before lodash.camelCase(paramName) to prevent runtime errors (line 166)
  • Fixed getContentTypes() to pass required 2 arguments instead of 1 (line 417)

Formatting:

  • Applied biome formatting fixes (line breaks and spacing)

Verification:

  • All tests pass (134 tests)
  • Build succeeds
  • Code review completed
  • Security scan passed (0 alerts)
  • Biome formatting applied

The changes improve code readability, remove TypeScript error suppressions, and add proper type validation to prevent runtime errors.

Original prompt
Please apply the following diffs and create a pull request.
Once the PR is ready, give it a title based on the messages of the fixes being applied.

[{"message":"[nitpick] The parameter name 'routeInfoByMethodsMap' is ambiguous and verbose. Consider renaming it to 'routesByMethod' or 'routeMethodsMap' for better clarity.","fixFiles":[{"filePath":"src/schema-routes/schema-routes.ts","diff":"diff --git a/src/schema-routes/schema-routes.ts b/src/schema-routes/schema-routes.ts\n--- a/src/schema-routes/schema-routes.ts\n+++ b/src/schema-routes/schema-routes.ts\n@@ -65,11 +65,11 @@\n     ]);\n   }\n \n-  createRequestsMap = (routeInfoByMethodsMap) => {\n-    const parameters = lodash.get(routeInfoByMethodsMap, \"parameters\");\n+  createRequestsMap = (routesByMethod) => {\n+    const parameters = lodash.get(routesByMethod, \"parameters\");\n \n     return lodash.reduce(\n-      routeInfoByMethodsMap,\n+      routesByMethod,\n       (acc, requestInfo, method) => {\n         if (\n           method.startsWith(\"x-\") ||\n"}]},{"message":"[nitpick] The parameter name 'originalRouteName' could be more concise. Consider renaming it to 'routeName' or 'rawRoute' for better readability.","fixFiles":[{"filePath":"src/schema-routes/schema-routes.ts","diff":"diff --git a/src/schema-routes/schema-routes.ts b/src/schema-routes/schema-routes.ts\n--- a/src/schema-routes/schema-routes.ts\n+++ b/src/schema-routes/schema-routes.ts\n@@ -91,10 +91,10 @@\n     );\n   };\n \n-  parseRouteName = (originalRouteName) => {\n+  parseRouteName = (rawRoute) => {\n     const routeName =\n-      this.config.hooks.onPreBuildRoutePath(originalRouteName) ||\n-      originalRouteName;\n+      this.config.hooks.onPreBuildRoutePath(rawRoute) ||\n+      rawRoute;\n \n     // TODO forbid leading symbols [\\]^` in a major release (allowed yet for backwards compatibility)\n     const pathParamMatches = (routeName || \"\").match(\n"}]},{"message":"TypeScript error is being suppressed without proper type checking. The 'paramName' variable should be validated as a string before calling 'includes' method to prevent runtime errors.","fixFiles":[{"filePath":"src/schema-routes/schema-routes.ts","diff":"diff --git a/src/schema-routes/schema-routes.ts b/src/schema-routes/schema-routes.ts\n--- a/src/schema-routes/schema-routes.ts\n+++ b/src/schema-routes/schema-routes.ts\n@@ -157,8 +157,7 @@\n       );\n \n       for (const paramName of paramNames) {\n-        // @ts-expect-error TS(2339) FIXME: Property 'includes' does not exist on type 'unknow... Remove this comment to see the full error message\n-        if (paramName.includes(\"-\")) {\n+        if (typeof paramName === \"string\" && paramName.includes(\"-\")) {\n           consola.warn(\"wrong query param name\", paramName);\n         }\n \n"}]},{"message":"TypeScript error is being suppressed without proper type validation. The 'paramName' should be validated as a string before passing to 'lodash.camelCase' to prevent runtime errors.","fixFiles":[{"filePath":"src/schema-routes/schema-routes.ts","diff":"diff --git a/src/schema-routes/schema-routes.ts b/src/schema-routes/schema-routes.ts\n--- a/src/schema-routes/schema-routes.ts\n+++ b/src/schema-routes/schema-routes.ts\n@@ -164,8 +164,7 @@\n \n         queryParams.push({\n           $match: paramName,\n-          // @ts-expect-error TS(2345) FIXME: Argument of type 'unknown' is not assignable to pa... Remove this comment to see the full error message\n-          name: lodash.camelCase(paramName),\n+          name: typeof paramName === \"string\" ? lodash.camelCase(paramName) : lodash.camelCase(String(paramName)),\n           required: true,\n           type: \"string\",\n           description: \"\",\n"}]},{"message":"Method call has incorrect number of arguments. The 'getContentTypes' method expects 2 arguments but only receives 1, which could lead to unexpected behavior.","fixFiles":[{"filePath":"src/schema-routes/schema-routes.ts","diff":"diff --git a/src/schema-routes/schema-routes.ts b/src/schema-routes/schema-routes.ts\n--- a/src/schema-routes/schema-routes.ts\n+++ b/src/schema-routes/schema-routes.ts\n@@ -417,7 +417,7 @@\n       requestInfos,\n       (acc, requestInfo, status) => {\n         // @ts-expect-error TS(2554) FIXME: Expected 2 arguments, but got 1.\n-        const contentTypes = this.getContentTypes([requestInfo]);\n+        const contentTypes = this.getContentTypes([requestInfo], operationId);\n \n         return [\n           ...acc,\n"}]}]

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.


Note

Renames parameters for clarity, adds string guards for query param handling, and passes the required second argument to getContentTypes in schema route processing.

  • Refactor
    • Rename createRequestsMap arg routeInfoByMethodsMaproutesByMethod and update internal usage.
    • Rename parseRouteName arg originalRouteNamerawRoute; set result.originalRoute to rawRoute.
  • Type safety
    • Add string checks before paramName.includes("-") and lodash.camelCase(paramName) when building query params.
  • Behavioral fix
    • Call getContentTypes([requestInfo], operationId) instead of with a single argument in getRequestInfoTypes.

Written by Cursor Bugbot for commit 1406d6d. This will update automatically on new commits. Configure here.

Copilot AI self-assigned this Oct 30, 2025
@changeset-bot
Copy link

changeset-bot bot commented Oct 30, 2025

⚠️ No Changeset found

Latest commit: 1406d6d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

- 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]>
Copilot AI changed the title [WIP] Refactor ambiguous parameter name in createRequestsMap Refactor parameter naming and remove TypeScript error suppressions Oct 30, 2025
Copilot AI requested a review from smorimoto October 30, 2025 01:26
Copilot finished work on behalf of smorimoto October 30, 2025 01:26
@smorimoto
Copy link
Collaborator

@copilot Run “yarn fix” and then run “yarn test -u”

Copy link
Contributor Author

Copilot AI commented Oct 30, 2025

@copilot Run “yarn fix” and then run “yarn test -u”

Done. Applied biome formatting fixes and ran tests with snapshot update. All 134 tests pass. (1406d6d)

Copilot finished work on behalf of smorimoto October 30, 2025 01:33
@smorimoto smorimoto marked this pull request as ready for review October 30, 2025 01:35
Copilot AI review requested due to automatic review settings October 30, 2025 01:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR focuses on code cleanup and type safety improvements by removing TypeScript error suppressions and improving parameter naming. The changes address type checking issues without suppressing errors.

  • Renamed parameters for better clarity (routeInfoByMethodsMaproutesByMethod, originalRouteNamerawRoute)
  • Added proper type guards for string parameters before using string methods
  • Fixed a function call with missing required argument

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +165 to +168
name:
typeof paramName === "string"
? lodash.camelCase(paramName)
: lodash.camelCase(String(paramName)),
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional handling of paramName is redundant. Since paramNames is derived from string operations (splitting and replacing), all elements should already be strings. The typeof paramName === 'string' check and the fallback String(paramName) add unnecessary complexity. Consider simplifying to just lodash.camelCase(paramName) or adding an assertion if type safety is the concern.

Suggested change
name:
typeof paramName === "string"
? lodash.camelCase(paramName)
: lodash.camelCase(String(paramName)),
name: lodash.camelCase(paramName),

Copilot uses AI. Check for mistakes.
for (const paramName of paramNames) {
// @ts-expect-error TS(2339) FIXME: Property 'includes' does not exist on type 'unknow... Remove this comment to see the full error message
if (paramName.includes("-")) {
if (typeof paramName === "string" && paramName.includes("-")) {
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type guard typeof paramName === 'string' appears unnecessary here. The paramNames array is populated from string operations (splitting comma-separated values from regex matches), so all elements should already be strings. This check adds defensive programming but may indicate uncertainty about the data type. Consider simplifying or documenting why non-string values are expected.

Copilot uses AI. Check for mistakes.
(acc, requestInfo, status) => {
// @ts-expect-error TS(2554) FIXME: Expected 2 arguments, but got 1.
const contentTypes = this.getContentTypes([requestInfo]);
const contentTypes = this.getContentTypes([requestInfo], operationId);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Incorrect Argument Type Causes Spread Operator Error

The getContentTypes method receives operationId (a string) as its second argument, but it expects an array. This causes the spread operator to iterate over the string's characters, leading to incorrect content type processing.

Fix in Cursor Fix in Web

@smorimoto smorimoto merged commit 13d26a6 into main Oct 30, 2025
17 checks passed
@smorimoto smorimoto deleted the copilot/refactor-route-parameter-naming branch October 30, 2025 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants