SwashBuckle 自定义操作标签

SwashBuckle Customising Operation Tags

我只是想从 swagger 文档中删除控制器一词。我看过使用 IOperationFilter 或 IDocumentFilter 手动编辑标签,但属性是只读的。

/// <summary>
/// Home
/// </summary>
public class HomeController : ApiController
{

}

我已根据 GitHub 上的文档启用了 XmlComments。除了无法更改控制器的描述外,我没有任何其他问题。

 private static string GetXmlCommentsPath()
 {
     return string.Format(@"{0}\bin\Sample.WebApi.XML", System.AppDomain.CurrentDomain.BaseDirectory);
 }

并且在 Swaggerconfig 中:-

 c.IncludeXmlComments(GetXmlCommentsPath());

如果您的意思是从操作组列表中删除 "controller"(默认为控制器名称),那么在您的 SwaggerConfig.cs 中,您可以使用 GroupActionsBy 选项:

c.GroupActionsBy(apiDesc =>
{
    return apiDesc.ActionDescriptor.ControllerDescriptor.ControllerName.Replace("Controller", "");
}