我想在Swagger中更改控制器的名称.

我正在使用.NET 5、Swashback 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中看到旧控制器名称下没有列出任何内容:

enter image description here

如何从Swagger中删除旧的控制器名称?

推荐答案

通过删除控制器上方的此注释,我可以从swagger UI中删除旧的控制器名称:

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

Csharp相关问答推荐

try 在C#中启动Tunnelbear.Exec

System.Text.Json:反序列化返回为空数组的字典时出错

减少Express Func T、bool断言中的公式中使用的条件运算符(4)数量(最多允许3个)

在包含空项的列表上使用具有断言T的摘要表

使用C#中的Shape API从Azure目录获取所有用户

如何从泛型方法返回一个可为空的T,其中T:notnull?

找不到网址:https://localhost:7002/Category/Add?区域= Admin.为什么我的URL是这样生成的?area = Admin而不是/Admin/

. NET在上一个操作完成之前,在此上下文实例上启动了第二个操作

使用LayoutKind在C#中嵌套 struct .显式

Mongo作为.NET中Testcontainers的副本集

Automapper 12.x将GUID映射到字符串

使用Entity Framework6在对象中填充列表会导致列表大多为空

为什么AggregateException的Catch块不足以处理取消?

对于PowerShell中的ConvertTo-SecureString方法,Microsoft如何将初始化向量添加到AES加密中的安全字符串?

MSTest--将消息直接写入StdOut和使用TestContext有什么不同?

为值对象编写自定义JsonConverter

.NET8->;并发词典总是比普通词典快...怎么回事?[包含基准结果和代码]

我的命名管道在第一次连接后工作正常,但后来我得到了System.ObjectDisposedException:无法访问关闭的管道

Blazor服务器项目中的Blazor/.NET 8/Web API不工作

使DefaultIfEmpty返回空