ASP .NET Boilerplate Swagger XML documentation for Controllers not visible

698 Views Asked by At

I created an Angular SPA Project using the asp boilerplate template and added a summary to the implementation of the controller for a sample function as suggested in this issue.

/// <summary>
/// This is my sample function
/// </summary>
/// <returns></returns>
public Task SummaryTestMethod()
{
    return Task.CompletedTask;
}

However, the swagger UI does not seem to register my remarks. I have not changed any other part in the code so far. Shouldn't the default configuration include the remarks? What could be the issue?

1

There are 1 best solutions below

2
On

You could follow the steps:

1.Enable the creation of XML documentation.In the Solution Explorer, right-click the project and click Properties. Click the Build tab and navigate to Output. Make sure that the XML documentation file option is checked. You can leave the default file path:

enter image description here

2.You need to make some changes to our Startup.cs file to tell swagger to use those comments:

services.AddSwaggerGen(c =>
{
    //1.locate the xml file being generated
    //if you choose the default file path in the first step,
    //the file name is SolutionName.xml
    //the file path is the project path
    var xmlFile = $"{Assembly.GetEntryAssembly().GetName().Name}.XML";
    var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);

    //2.tell swagger to use those xml comments
    c.IncludeXmlComments(xmlPath);
    //...
}

Result:

enter image description here

Reference:

https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-3.1&tabs=visual-studio#xml-comments