DEV Community

Supraja Tangella
Supraja Tangella

Posted on

๐—˜๐˜…๐—ฝ๐—น๐—ผ๐—ฟ๐—ถ๐—ป๐—ด ๐—ข๐—ฝ๐—ฒ๐—ป๐—”๐—ฃ๐—œ ๐—–๐˜‚๐˜€๐˜๐—ผ๐—บ๐—ถ๐˜‡๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ถ๐—ป ๐—”๐—ฆ๐—ฃ.๐—ก๐—˜๐—ง ๐—–๐—ผ๐—ฟ๐—ฒ ๐— ๐—ถ๐—ป๐—ถ๐—บ๐—ฎ๐—น ๐—”๐—ฃ๐—œ๐˜€

Over the past few days, Iโ€™ve been working with ๐—ข๐—ฝ๐—ฒ๐—ป๐—”๐—ฃ๐—œ ๐—ฑ๐—ผ๐—ฐ๐˜‚๐—บ๐—ฒ๐—ป๐˜๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ถ๐—ป ๐—”๐—ฆ๐—ฃ.๐—ก๐—˜๐—ง ๐—–๐—ผ๐—ฟ๐—ฒ, going beyond the basics of AddSwaggerGen() by using a more advanced and modular approach with AddOpenApi().

Key things I learned:

The difference between AddSwaggerGen() (Swashbuckle) and AddOpenApi() (OpenAPI.NET-based).
How to use ๐——๐—ผ๐—ฐ๐˜‚๐—บ๐—ฒ๐—ป๐˜, ๐—ข๐—ฝ๐—ฒ๐—ฟ๐—ฎ๐˜๐—ถ๐—ผ๐—ป, ๐—ฎ๐—ป๐—ฑ ๐—ฆ๐—ฐ๐—ต๐—ฒ๐—บ๐—ฎ ๐—ง๐—ฟ๐—ฎ๐—ป๐˜€๐—ณ๐—ผ๐—ฟ๐—บ๐—ฒ๐—ฟ๐˜€ to fully control the OpenAPI output.
Automatically adding security schemes, licensing info, and contact metadata using transformer methods.
How these tools help create clear, interactive API docs for clients or frontend teams.

๐˜€๐—บ๐—ฎ๐—น๐—น ๐˜€๐—ป๐—ถ๐—ฝ๐—ฝ๐—ฒ๐˜ :

builder.Services.AddOpenApi("v2", options => {
options.AddDocumentTransformer(new AddContactTransformer());
options.AddOperationTransformer();
options.AddDocumentTransformer((doc, ctx, token) => {
doc.Info.License = new OpenApiLicense { Name = "MIT" };
return Task.CompletedTask;
});
});

Itโ€™s been exciting to see how customizable and powerful OpenAPI can be when documenting minimal APIs properly.

If you're building public or internal APIs, I highly recommend exploring these transformers to give your documentation a professional edge!

Top comments (0)