在Swagger中显示不同的控制器名称

发布于 2025-02-12 13:28:09 字数 972 浏览 1 评论 0原文

我想用大招牌更改控制器的名称。

我正在使用.net 5,swashbuckle aspnetcore v6.3.1,并具有此启动代码:

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

控制器:

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

它似乎很好,除了我仍然可以看到旧的控制器名称,swagger下没有列出任何内容:

“在此处输入图像说明”

如何从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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卷耳 2025-02-19 13:28:10

通过在控制器上方删除此评论,我能够从Swagger UI中删除旧的控制器名称:

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

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 {}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文