Swashbuckle.AspNetCore
Swashbuckle.AspNetCore copied to clipboard
SwaggerGenOptions.IncludeXmlComments does not support /// <inheritdoc />
To replicate:
- Create a new
ASP.NET Core Web API
project.
dotnet new webapi
-
Set
<GenerateDocumentationFile>
totrue
in.csproj
. -
In
Program.cs
, replacebuilder.Services.AddSwaggerGen();
with:
builder.Services.AddSwaggerGen(
swaggerGenConfiguration =>
{
var assembly = System
.Reflection
.Assembly
.GetExecutingAssembly()
;
var assemblyName = assembly
.GetName()
.Name
;
var xmlFile = $"{assemblyName}.xml";
var xmlPath = Path.Combine(
AppContext.BaseDirectory,
xmlFile
);
swaggerGenConfiguration.IncludeXmlComments(
xmlPath
);
}
);
- Insert the following before
[HttpGet(Name = "GetWeatherForecast")]
:
/// <summary>
/// This is my XML documentation comment!
/// </summary>
- Modify
[HttpGet(Name = "GetWeatherForecast")]
with the following:
[HttpGet("GetWeatherForecast")]
- Create a new type that extends
WeatherForecastController
, such as:
/// <summary>
/// Extends <see cref="WeatherForecastController" />.
/// </summary>
public class WeatherForecastController2
: WeatherForecastController
{
/// <summary>
/// Create a new instance.
/// </summary>
/// <param name="logger">
/// The logger.
/// </param>
public WeatherForecastController2(
ILogger<WeatherForecastController> logger
)
: base(
logger
)
{
}
/// <inheritdoc />
public override IEnumerable<WeatherForecast> Get()
=> base.Get();
}
- Run the project
dotnet run
- Navigate to Swagger UI.
- Observe how the deriving type does not show the XML documentation comment with the action.
- Replace the XML documentation of the deriving type with the following:
/// <summary>
/// This is my XML documentation comment without inheriting from the base type!
/// </summary>
- Run the project
dotnet run
- Observe how the deriving type does show the replaced XML documentation comment with the action.