OpenAPITools / OpenAPITools/openapi-generator

[BUG] Dashed (-) are transformed to underscores (_)

Open
#4,065 9 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: TypeScript 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)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

I am using openapi-generator with typescript-fetch plugin:

openapi-generator generate -g typescript-fetch --additional-properties=supportsES6=true,typescriptThreePlus=true,modelPropertyNaming=original -o ./open-api -i ./apigateway.json

for some reason, the generator alsways transforms properties adv_1-1 to adv_1_1. meaning, it removes the original -.

spec:

"prices": {
            "type": "object",
            "properties": {
              "adv_1-1": {
                "type": "number"
              },
              "adv_1-2": {
                "type": "number"
              },
              "adv_1-3": {
                "type": "number"
              },
              "adv_1-4": {
                "type": "number"
              },
              "adv_1-6": {
                "type": "number"
              },
              "adv_2-1": {
                "type": "number"
              },
              "adv_2-3": {
                "type": "number"
              },
              "migrateId": {
                "type": "number"
              },
              "mm": {
                "type": "number"
              }
            }
          }

result:

export interface MediaPrintPrices {
    /**
     *
     * @type {number}
     * @memberof MediaPrintPrices
     */
    adv_1_1?: number;
    /**
     *
     * @type {number}
     * @memberof MediaPrintPrices
     */
    adv_1_2?: number;
    /**
     *
     * @type {number}
     * @memberof MediaPrintPrices
     */
    adv_1_3?: number;
    /**
     *
     * @type {number}
     * @memberof MediaPrintPrices
     */
    adv_1_4?: number;
    /**
     *
     * @type {number}
     * @memberof MediaPrintPrices
     */
    adv_1_6?: number;
    /**
     *
     * @type {number}
     * @memberof MediaPrintPrices
     */
    adv_2_1?: number;
    /**
     *
     * @type {number}
     * @memberof MediaPrintPrices
     */
    adv_2_3?: number;
    /**
     *
     * @type {number}
     * @memberof MediaPrintPrices
     */
    migrateId?: number;
    /**
     *
     * @type {number}
     * @memberof MediaPrintPrices
     */
    mm?: number;
}
openapi-generator version

4.1.2

OpenAPI declaration file content or url
Command line used for generation
openapi-generator generate -g typescript-fetch --additional-properties=supportsES6=true,typescriptThreePlus=true,modelPropertyNaming=original -o ./open-api -i ./apigateway.json

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 the typescript-fetch generator using the command and OpenAPI properties shown in the issue, especially modelPropertyNaming=original. Compare generated property names containing hyphens with the specification, then verify that the generated TypeScript interface preserves those names without changing unrelated properties.

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
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.