I have a small project in .NET 6 that contains minimal APIs like that one
app.MapGet("/clients",
async (IClientRepository repo) =>
{
var results = await repo.GetClientsAsync();
return mapper.Map<IEnumerable<ClientModel>>(results);
});
In the SwaggerUI
I can use this API but I can't find a way to add description to it (although in the project settings I check for creating an API XML documentation).
How can I add the XML comment?
1. Install package
dotnet add package Swashbuckle.AspNetCore.Annotations
2. Write code
// Program.cs
builder.Services.AddSwaggerGen(x =>
{
x.EnableAnnotations();
});
// app.MapGet("/hi", [SwaggerOperation(Summary = "summary001", Description = "description001 `adads`")] () => "Hi");
app.MapGet("/hi", () => "Hi")
.WithMetadata(new SwaggerOperationAttribute("summary001", "description001"));