OpenAPITools / OpenAPITools/openapi-generator

[BUG][TYPESCRIPT][AXIOS] Request parameter named "configuration" collides in typescript-axios generation

Open
#17,604 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
    • Actual output: Invalid API client code, generated with TypeScript errors because of colliding variable names and will not run
    • Expected output: Valid API client code
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When an endpoint parameter has the name "configuration," this breaks the generated code for the typescript-axios generator because the name collides with the configuration object used in the base API.

Here are just a few other parameter names that would cause similar issues (this is not an exhaustive list, but these are the most common words).

  • options
  • index
  • baseOptions
  • basePath

Here's a full example repository, and a pull request just to show the typescript errors from the generated code:

openapi-generator version
OpenAPI declaration file content or url
{
  "openapi": "3.0.1",
  "info": {
    "title": "Example API",
    "version": "v1"
  },
  "paths": {
    "/api/config": {
      "post": {
        "operationId": "UpdateConfig",
        "parameters": [
          {
            "name": "configuration",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          }
        }
      }
    }
  }
}
Generation Details

openapitools.json:

{
  "$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
  "spaces": 2,
  "generator-cli": {
    "version": "7.2.0",
    "generators": {
      "api": {
        "generatorName": "typescript-axios",
        "glob": "./openapi.json",
        "output": "./src"
      }
    }
  }
}
Steps to reproduce
  1. Generate with the above openapi generator config and spec

See example repo/PR: https://github.com/hiddenist/example-openapi-generation/pull/1/files

Related issues/PRs
Suggest a fix

Ideally, the generated function parameter names should avoid colliding with a restricted list of tokens that are used in the generated code. That, or the generated code should be updated to namespace its variables with something to make it unlikely to collide.

I have a workaround that I've been using in my own codebase for a while where I grep out every instance of "configuration" in my json spec before generating, and replace it again within strings in the built out paths, but this isn't ideal. I can't change the API itself in this case since there are other consumers that need the API to stay the same.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with openapi.json and openapitools.json in the linked example repository, then generate the typescript-axios client using generator version 7.2.0. Inspect the generated code for collisions between endpoint parameters and the base API configuration variables; done means the example generates valid TypeScript without collisions while preserving the API parameter name.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.