cyclosproject / ng-openapi-gen

An OpenAPI 3.0 codegen for Angular
MIT License
397 stars 132 forks source link

Enums are not correctly generated #40

Closed SharmaHarsh7 closed 4 years ago

SharmaHarsh7 commented 5 years ago

Hi,

I recently observed that it is generating Enums as following:

/* tslint:disable */

/**
 * 10 = NationalHoliday
 * 20 = Festival
 */
export enum HolidayType {
  10 = 10,
  20 = 20
}

Where it is using the numerical part only, it would be really helpful if you could replace the LHS part with the actual String representation as shown in commented code above.

Thanks

kervi commented 5 years ago

I have experienced something similar.

The specification:

"StateType": {
        "type": "integer",
        "description": "",
        "x-enumNames": [
          "Pending",
          "Ready",
          "Published",
          "Closed",
          "Retracted"
        ],
        "enum": [
          1,
          2,
          3,
          4,
          5
        ]
      },

generated ts code:

export enum StateType { 1 = 1, 2 = 2, 3 = 3, 4 = 4, 5 = 5 }

expected ts code:

export enum StateType { Pending = 1, Ready = 2, Published = 3, Closed = 4, Retracted = 5 }

tim-elektron-fo commented 5 years ago

I have made a pull request that solves this issue: Pull request

luisfpg commented 5 years ago

There are actually 2 issues here:

  1. Integer enums generate invalid identifiers: leaving this one for it
  2. Support the x-enumNames extension: Created #44 for it
sudoman281 commented 5 years ago

The workaround for this is to force Swagger to describe enums as strings instead of integers. You do that by adding c.DescribeAllEnumsAsStrings(); inside the services.AddSwaggerGen(c => ....