Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XmlCommentsDocumentFilter incorrect comment controller tags names. #2717

Closed
MerickOWA opened this issue Sep 28, 2023 · 2 comments · Fixed by #2718
Closed

XmlCommentsDocumentFilter incorrect comment controller tags names. #2717

MerickOWA opened this issue Sep 28, 2023 · 2 comments · Fixed by #2718

Comments

@MerickOWA
Copy link
Contributor

MerickOWA commented Sep 28, 2023

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

Copy link
Contributor

This issue is stale because it has been open for 60 days with no activity. It will be automatically closed in 14 days if no further updates are made.

@github-actions github-actions bot added the stale Stale issues or pull requests label Apr 14, 2024
@martincostello martincostello removed the stale Stale issues or pull requests label Apr 14, 2024
@martincostello
Copy link
Collaborator

#2718 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants