Skip to content

XmlCommentsDocumentFilter incorrect comment controller tags names. #2717

@MerickOWA

Description

@MerickOWA

In Swashbuckle.AspNetCore.SwaggerGen v6.5.0

There appears to be a bug in XmlCommentsDocumentFilter.cs

Simple reproduction steps are to create an [ApiController] and set a [ControllerName(...)] attribute on it which overrides the controller's name to something else, example:

// simple setup with including xml comments
services.AddSwaggerGen(c =>
{
    c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
    c.IncludeXmlComments(..., includeControllerXmlComments: true);
});

/// <summary>
/// My test controller to prove bugs
/// </summary>
[ApiController]
[Route("api/test")]
[ControllerName("Test")]
public class MyTestController : ControllerBase
{
    /// <summary>
    /// Returns something else
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public IActionResult Index()
    {
        return Ok(new { Something = "Hello", Else = "World" });
    }
}

The default SwaggerGeneratorOptions.TagsSelector uses the RouteValues["controller"] as the tag it puts on actions, but the XmlCommentsDocumentFilter.cs will create the tag using ControllerName which is the original/raw name (minus the Controller suffix if it exists).

This leads to ReDoc and Swagger UI to show an extra section with the raw controller name and the comment, and a separate section with the action actions.

Expected behavior would be that controller comments properly show up under the "Test" section.

image

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions