Nowadays we can use Swagger like a documentation about our API's. To help others to understand our rules when we use Enums, I'll demonstrate how we can present at Swagger our Enums as string not with magic numbers.
To this article I'll use this project swagger-enums-asstring at my GitHub.
To do this is very easy, we just need to put this code bellow at Program.cs file.
builder.Services.AddControllers()
.AddJsonOptions(options =>
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()));
Running our project We can see the result at image bellow:
Top comments (0)