David Klempfner
David Klempfner

Reputation: 9868

Display different controller name in Swagger

I would like to change the name of the controller in Swagger.

I'm using .NET 5, Swashbuckle AspNetCore v6.3.1 and have this Startup code:

public void ConfigureServices(IServiceCollection services)
{
    // code omitted for brevity
    services.AddSwaggerGenNewtonsoftSupport();
    services.AddSwaggerGen(x => x.EnableAnnotations());
}

Controller:

[Route("v1/taggroups")]
[ApiController]
public class ProfileGroupTypesController : ControllerBase
{
    [HttpPost]
    [SwaggerOperation(OperationId = "Add Tag Group", Tags = new[] { "TagGroups" })]
    public IActionResult CreateProfileGroupType([FromBody] CreateProfileGroupTypeRequest request)
    {
             
    }
}

It seems to work well, except I can still see the old controller name with nothing listed under it in Swagger:

enter image description here

How can I remove the old controller name from Swagger?

Upvotes: 3

Views: 2379

Answers (1)

David Klempfner
David Klempfner

Reputation: 9868

By removing this comment above my controller, I was able to remove the old controller name from the swagger UI:

    /// <summary>
    /// ProfileGroupTypes Controller // REMOVE THIS
    /// </summary>
    [Route("v1/taggroups")]
    [ApiController]
    public class ProfileGroupTypesController : ControllerBase {}

Upvotes: 1

Related Questions