fabien0102 / openapi-codegen

A tool for generating code base on an OpenAPI schema.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

useEnums with numeric values or strings with spaces in swagger

bradrisse opened this issue · 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