User friendly enums in Swagger UI with .NET 6

When using enums in a .NET API that has Swagger UI (with Swashbuckle), they are shown as numbers by default. I found this not very user friendly as you’d need insight in what the number represents. After some googling, I found this solution: 1. Add a Enum Schema Filter using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.SwaggerGen; namespace Your.Namespace; public class EnumSchemaFilter : ISchemaFilter { public void Apply(OpenApiSchema schema, SchemaFilterContext context) { if (context....

September 8, 2022 · 2 min · Thomas de Wulf

Hello World

Hello world!

1 min · Thomas de Wulf