openapi-typescript-codegen icon indicating copy to clipboard operation
openapi-typescript-codegen copied to clipboard

Invalid enum name generation for property names containing hyphens

Open christianvogt opened this issue 3 years ago • 1 comments

Describe the bug Invalid enum name generation for property names containing hyphens.

Sample api:

{
  "openapi": "3.0.0",
  "info": {
    "version": "1.0.0"
  },
  "components": {
    "schemas": {
      "TestModel": {
        "properties": {
          "rates": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Testing"
            }
          }
        }
      },
      "Testing": {
        "properties": {
          "test-hyphen": {
            "type": "string",
            "enum": ["First", "Second"]
          }
        }
      }
    }
  }
}

Output Testing.ts:

export type Testing = {
    'test-hyphen'?: Testing.'test-hyphen';
};

export namespace Testing {

    export enum 'test-hyphen' {
        FIRST = 'First',
        SECOND = 'Second',
    }
}
image

christianvogt avatar Aug 29 '22 17:08 christianvogt

Hitting the same issue when trying to generate code from Flink OpenAPI

https://nightlies.apache.org/flink/flink-docs-release-1.15/generated/rest_v1_dispatcher.yml

I don't own this OpenAPI, so I can't add x-enum-varnames to workaround it.

Perhaps there can be a logic to automatically convert such names to CamelCase?

tigerinus avatar Oct 05 '22 00:10 tigerinus