Closed SharmaHarsh7 closed 4 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 }
I have made a pull request that solves this issue: Pull request
There are actually 2 issues here:
x-enumNames
extension: Created #44 for itThe 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 => ...
.
Hi,
I recently observed that it is generating Enums as following:
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