Swager-codegenerator generates bad enum names for C#. The enums naming is
NUMBER_X where X is the enum's
int value from swashbuckle swagger doc in MVC5
Using the Swager-codegenerator java tool to generate a swager REST client targeting C# (and potentially other languages), I ended up getting enums with a name based on their integer value instead of the normal maping between a name and a value.
Given the enum's source code on the web API side as follows:
the result looked like this:
As it turns out, the problem is not at all wihtin the code generation tool, but with the generated spec itself.
After taking a look at the swagger doc generated by swashbuckle I noticed that the enumeration was represented using the following definition, which contained no information regarding the string names associated with the integer values:
To fix this, I added the
c.DescribeAllEnumsAsStrings(); line in the call to
GlobalConfiguration.Configuration.EnableSwagger. This tells the swagger doc generator to represent enums using the "name" of each enum value as a string.
After this modification, the generated swagger doc looked like this:
and the generated code like this: