Swagger and Enums in C#

September 8, 2016

By default, if you expose a service that has an Enum as a parameter, Swashbuckle will expose it using the index numbers of the enum in a dropdown. So in my case, given:

public enum TimeBasis { REALTIME, SLOW, FAST }

I got a droplist with 0, 1 and 2 in it. Not useful.

You can configure Swagger/Swashbuckle to use the string names instead. In SwaggerConfig.cs, uncomment c.DescribeAllEnumsAsStrings();

I now get a droplist that contains REALTIME, SLOW and FAST.

References