I am trying to add enums as parameters for my Swagger endpoint but they are being displayed as integers:

On the old .NET there was an option for Swagger option.DescribeAllEnumsAsStrings(); but I don't have it on .NET 6:

I tried adding:
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
but it is still not showing my enums as strings.
I found the same issue here, and I test the workaround mentioned in the question in my side and it worked for me.
In Program.cs,
Append .AddJsonOptions(options => { options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); }); behind builder.Services.AddControllers()
The code should look like:
using System.Text.Json.Serialization;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers()
.AddJsonOptions(options => { options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); });

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With