Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enums are not correctly generated #40

Closed
SharmaHarsh7 opened this issue Aug 17, 2019 · 4 comments
Closed

Enums are not correctly generated #40

SharmaHarsh7 opened this issue Aug 17, 2019 · 4 comments
Labels
bug Something isn't working
Milestone

Comments

@SharmaHarsh7
Copy link

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
Copy link

kervi commented Aug 28, 2019

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
Copy link

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

@luisfpg
Copy link
Contributor

luisfpg commented Aug 30, 2019

There are actually 2 issues here:

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

@luisfpg luisfpg added the bug Something isn't working label Aug 30, 2019
@sudoman281
Copy link

sudoman281 commented Oct 22, 2019

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 => ....

@luisfpg luisfpg added this to the 0.7.0 milestone Dec 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants