Skip to content

Enum parsing key of negative numbers #991

@tiberiuzuld

Description

@tiberiuzuld

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions