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)