今天使用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;
}
}

浙公网安备 33010602011771号