OpenAPITools / OpenAPITools/openapi-generator

TypeScript-Axios Generator Creates Interface Properties with Single Quotes

Open
#20,772 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

When using the typescript-axios generator to create TypeScript interfaces from an OpenAPI spec, all property names in the generated interfaces are surrounded by single quotes, which is not the preferred TypeScript syntax style.
For example, the generated interface looks like:

export interface UserProfileDto {
    /**
     * The unique identifier for the user
     * @type {number}
     * @memberof UserProfileDto
     */
    'id': number;
    /**
     * The username of the user
     * @type {string}
     * @memberof UserProfileDto
     */
    'username': string;
    /**
     * The email address of the user
     * @type {string}
     * @memberof UserProfileDto
     */
    'email': string;
    /**
     * The first name of the user
     * @type {string}
     * @memberof UserProfileDto
     */
    'firstName': string;
    // ... more properties
}

But I want the standard TypeScript interface style without quotes:

export interface UserProfileDto {
    /**
     * The unique identifier for the user
     * @type {number}
     * @memberof UserProfileDto
     */
    id: number;
    /**
     * The username of the user
     * @type {string}
     * @memberof UserProfileDto
     */
    username: string;
    /**
     * The email address of the user
     * @type {string}
     * @memberof UserProfileDto
     */
    email: string;
    /**
     * The first name of the user
     * @type {string}
     * @memberof UserProfileDto
     */
    firstName: string;
    // ... more properties
}

Configuration Used
Here is my current OpenAPI Generator configuration:

{
    "$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
    "spaces": 2,
    "generator-cli": {
      "version": "7.11.0",
      "generators": {
        "typescript-types": {
          "generatorName": "typescript-axios",
          "output": "src/generated",
          "glob": "swagger.json",
          "skipValidateSpec": true,
          "additionalProperties": {
            "withSeparateModelsAndApi": true,
            "enumNameSuffix": "",
            "enumPropertyNaming": "UPPERCASE",
            "withInterfaces": true,
            "supportsES6": true,
            "modelPropertyNaming": "original",
            "modelPackage": "models",
            "apiPackage": "apis",
            "stringEnums": true
          }
        }
      }
    }
  }

Attempted Solutions

  1. Setting modelPropertyNaming: "original"
  2. Trying different generators (typescript-fetch, typescript-node)

Expected Behavior
The TypeScript interfaces should be generated with property names that don't have single quotes around them, following standard TypeScript syntax.

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

The issue names the typescript-axios generator but no repository files or tests. Reproduce the generated interfaces with the supplied configuration and an OpenAPI spec, then trace the generator output to identify where property names receive quotes. Done means generated valid-name properties use the requested unquoted TypeScript style without breaking names that require quoting.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.