DEV Community

Thiago da Silva Adriano
Thiago da Silva Adriano

Posted on

1

.NET 6 Swagger show enums as strings

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()));
Enter fullscreen mode Exit fullscreen mode

Running our project We can see the result at image bellow:

Image description

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay