Enums are not correctly generated
SharmaHarsh7 opened this issue · comments
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
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 }
I have made a pull request that solves this issue:
Pull request
There are actually 2 issues here:
- Integer enums generate invalid identifiers: leaving this one for it
- Support the
x-enumNames
extension: Created #44 for it
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 => ...
.