Steve
Steve

Reputation: 4503

Summary of the method documentation is not showing in Swagger UI

I have added the content in the summary tag but it not showing in the swagger ui in .NET 6 Web Api project.

enter image description here

    /// <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. enter image description here

Upvotes: 1

Views: 3220

Answers (1)

Nick Papadiochos
Nick Papadiochos

Reputation: 379

Here's what worked on my side (in a sample .NET 6 Web Api project):

  1. Go to the properties of your project => Build => General => Output section => Tick the checkbox 'XML Documentation file'

  2. 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);
});

PoC: enter image description here

Does this approach work for you?

Upvotes: 8

Related Questions