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

useEnums with numeric values or strings with spaces in swagger

Open bradrisse opened this issue 2 years ago • 0 comments

"status": {
  "type": "string",
   "enum": [
      "100",
      "101",
      "102",
      "103",
     "200",
    ]
 }

gets converted to

export enum SomeDefinition {
   100 = "100",
   101 = "101",
   102 = "102",
   103 = "103",
}

which causes an unexpected token error due to numeric enum key not being valid.

before converting swagger enum array to typescript enum, can the generator check to see if the enum key is possibly numeric and if so keep the key a string?

The other issue is also enums with spaces in the enum values

Maybe 'x-enumNames' like here https://stackoverflow.com/questions/66465888/how-to-define-enum-mapping-in-openapi

bradrisse avatar Jul 21 '23 18:07 bradrisse