Hello World ~~~

Fork me on GitHub
lucky528

导航

 

今天使用swagger,但是莫名其妙的把SharePoint server search的一些API 加载进来了,想要在swagger 的.NET framework版本中根据controller的 namespace过滤掉一些controller,查了一些资料。

https://github.com/domaindrivendev/Swashbuckle.WebApi/issues/1174

替换掉默认的ApiExplorer.

public class ApiCustomizeExplorer : System.Web.Http.Description.ApiExplorer
{
    public ApiCustomizeExplorer(HttpConfiguration configuration) : base(configuration)
    {
    
    }

    public override bool ShouldExploreController(string controllerVariableValue, HttpControllerDescriptor controllerDescriptor, IHttpRoute route)
    {
        if(controllerDescriptor.ControllerType.Namespace.StartsWith("WebApi.Controllers") && base.ShouldExploreController(controllerVariableValue, controllerDescriptor, route))
        {
            return true;
        }
        return false;

    }
}

  

posted on 2025-06-11 10:27  gopher666  阅读(10)  评论(0)    收藏  举报