Skip to content

Fix typescript axios options - #1429

Open
flashnoob wants to merge 4 commits into
swagger-api:masterfrom
flashnoob:fix-typescript-axios-options
Open

Fix typescript axios options#1429
flashnoob wants to merge 4 commits into
swagger-api:masterfrom
flashnoob:fix-typescript-axios-options

Conversation

@flashnoob

Copy link
Copy Markdown

Pull Request

Thank you for contributing to swagger-codegen-generators!

Description

Fix a parameter name collision in the typescript-axios generator when an OpenAPI operation defines a parameter named options.

The generator currently uses options for the Axios request configuration parameter. If an API operation also has a parameter named options, the generated TypeScript method contains duplicate parameter names.

For example, the generated method can contain:

options: Array<CoverageOptionPutRequest>,
authorization?: string,
options?: AxiosRequestConfig

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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 options to requestOptions across the ParamCreator, FP, Factory, Interface, and Class APIs.
  • Updates internal merges/usages to spread requestOptions into 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';
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.

3 participants