-
-
Notifications
You must be signed in to change notification settings - Fork 420
Refactor parameter naming and remove TypeScript error suppressions #1483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -65,11 +65,11 @@ export class SchemaRoutes { | |||||||||||
| ]); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| createRequestsMap = (routeInfoByMethodsMap) => { | ||||||||||||
| const parameters = lodash.get(routeInfoByMethodsMap, "parameters"); | ||||||||||||
| createRequestsMap = (routesByMethod) => { | ||||||||||||
| const parameters = lodash.get(routesByMethod, "parameters"); | ||||||||||||
|
|
||||||||||||
| return lodash.reduce( | ||||||||||||
| routeInfoByMethodsMap, | ||||||||||||
| routesByMethod, | ||||||||||||
| (acc, requestInfo, method) => { | ||||||||||||
| if ( | ||||||||||||
| method.startsWith("x-") || | ||||||||||||
|
|
@@ -91,10 +91,9 @@ export class SchemaRoutes { | |||||||||||
| ); | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| parseRouteName = (originalRouteName) => { | ||||||||||||
| parseRouteName = (rawRoute) => { | ||||||||||||
| const routeName = | ||||||||||||
| this.config.hooks.onPreBuildRoutePath(originalRouteName) || | ||||||||||||
| originalRouteName; | ||||||||||||
| this.config.hooks.onPreBuildRoutePath(rawRoute) || rawRoute; | ||||||||||||
|
|
||||||||||||
| // TODO forbid leading symbols [\]^` in a major release (allowed yet for backwards compatibility) | ||||||||||||
| const pathParamMatches = (routeName || "").match( | ||||||||||||
|
|
@@ -157,15 +156,16 @@ export class SchemaRoutes { | |||||||||||
| ); | ||||||||||||
|
|
||||||||||||
| 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("-")) { | ||||||||||||
| consola.warn("wrong query param name", paramName); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| queryParams.push({ | ||||||||||||
| $match: paramName, | ||||||||||||
| // @ts-expect-error TS(2345) FIXME: Argument of type 'unknown' is not assignable to pa... Remove this comment to see the full error message | ||||||||||||
| name: lodash.camelCase(paramName), | ||||||||||||
| name: | ||||||||||||
| typeof paramName === "string" | ||||||||||||
| ? lodash.camelCase(paramName) | ||||||||||||
| : lodash.camelCase(String(paramName)), | ||||||||||||
|
Comment on lines
+165
to
+168
|
||||||||||||
| name: | |
| typeof paramName === "string" | |
| ? lodash.camelCase(paramName) | |
| : lodash.camelCase(String(paramName)), | |
| name: lodash.camelCase(paramName), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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. TheparamNamesarray 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.