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

Created on 4 Oct 2019  路  5Comments  路  Source: OpenAPITools/openapi-generator

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [x] Have you validated the input using an OpenAPI validator (example)?
  • [x] What's the version of OpenAPI Generator used?
  • [x] Have you search for related issues/PRs?
  • [x] 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
TypeScript Bug

Most helpful comment

As seen in my example above, I already use original. In my opinion it should then keep the original structure of the properties.

All 5 comments

馃憤 Thanks for opening this issue!
馃彿 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@misantronic no expert in TS but is dash (-) allowed in the variable naming?

Ideally, we should be using a JSON serializer to handle this but I don't think we've found it suitable yet.

dashes are not allowed in variables, but that doesnt matter since they are allowed in literal object-properties.

Can you please try the following option?

    modelPropertyNaming
        Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name (Default: camelCase)

As seen in my example above, I already use original. In my opinion it should then keep the original structure of the properties.

Was this page helpful?
0 / 5 - 0 ratings