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

Enum parsing key of negative numbers

Open tiberiuzuld opened this issue 2 years ago • 0 comments

Hello,

We have the following situation where we have an Enum with negative and positive numbers as keys to the Enum and the keys generated in typescript collide for negative numbers with positive numbers.

Java code

public enum property {
    NOT_SET(-1, ""),
    NONE(0, "none"),
    SOME_VALUE(1, "some_value"),
    SOME_OTHER_VALUE(2, "some_other_value"),
    EXTRA_VALUE(3, "extra_value")
}

Swagger json

{
  "property": {
    "type": "string",
    "enum": [
      "-1",
      "0",
      "1",
      "2",
      "3"
    ]
  }
}

Generated Typescript

export namespace MyClass {
  export enum property {
    _1 = '-1',  // error same key
    _0 = '0',
    _1 = '1',   // error same key
    _2 = '2',
    _3 = '3'
  }
}

Possible issue here

tiberiuzuld avatar Mar 24 '22 17:03 tiberiuzuld