Fix typescript axios options - #1429
Open
flashnoob wants to merge 4 commits into
Open
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The template currently risks a runtime exception when requestOptions.params is undefined and also introduces optional chaining that can unnecessarily break compilation for users on older TypeScript versions.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates the typescript-axios Handlebars templates to avoid a generated TypeScript method parameter name collision when an OpenAPI operation defines a parameter named options (which previously conflicted with the Axios request config parameter).
Changes:
- Renames the generated Axios request config parameter from
optionstorequestOptionsacross theParamCreator, FP, Factory, Interface, and Class APIs. - Updates internal merges/usages to spread
requestOptionsinto the request config. - Adjusts the body serialization check to use optional chaining on
headers(now flagged for compatibility concerns).
File summaries
| File | Description |
|---|---|
| src/main/resources/handlebars/typescript-axios/apiInner.mustache | Renames the Axios config parameter to prevent collisions with user-defined options parameters in generated clients. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+194
to
196
| for (const key in requestOptions.params) { | ||
| query.set(key, requestOptions.params[key]); | ||
| } |
| {{^isForm}} | ||
| {{#bodyParam}} | ||
| const needsSerialization = (typeof {{paramName}} !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json'; | ||
| const needsSerialization = (typeof {{paramName}} !== "string") || localVarRequestOptions.headers?['Content-Type'] === 'application/json'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
Thank you for contributing to swagger-codegen-generators!
Description
Fix a parameter name collision in the
typescript-axiosgenerator when an OpenAPI operation defines a parameter namedoptions.The generator currently uses
optionsfor the Axios request configuration parameter. If an API operation also has a parameter namedoptions, the generated TypeScript method contains duplicate parameter names.For example, the generated method can contain: