To enable XML documentation such as comments on controllers to appear in swagger follow the following steps.
Enable XML document generation for the Assembly:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DocumentationFile>bin\Debug\netcoreapp3.1\PHDV.Deliveroo.Webhooks.Api.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DocumentationFile>bin\Release\netcoreapp3.1\PHDV.Deliveroo.Webhooks.Api.xml</DocumentationFile>
</PropertyGroup>
Add the path to the XML file to Swagger options in the Startup.cs:
services.AddSwaggerGen(options =>
{
var xmlFileName = $"{GetType().Assembly.GetName().Name}.xml";
var xmlFilePath = Path.Combine(AppContext.BaseDirectory, xmlFileName);
options.IncludeXmlComments(xmlFilePath);
options.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo
{
Title = _serviceName,
Version = "v1",
});
});