Reputation: 4503
I have added the content in the summary tag but it not showing in the swagger ui in .NET 6 Web Api project.
/// <summary>
/// Check if the trading account already closed
/// </summary>
/// <param name="nric">xxxxxx-xx-xxxx</param>
/// <returns></returns>
[HttpGet]
public async Task<ActionResult> IsAccountClosed(string nric)
{
// code is removed for brevity
}
This is default code in Program.cs
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
But in .NET Core 3.1 Web Api project, it shows.
Upvotes: 1
Views: 3220
Reputation: 379
Here's what worked on my side (in a sample .NET 6 Web Api project):
Go to the properties of your project => Build => General => Output section => Tick the checkbox 'XML Documentation file'
Edit the AddSwaggerGen
service configuration by adding the following:
builder.Services.AddSwaggerGen(c =>
{
...
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
Does this approach work for you?
Upvotes: 8