我们有一个带有常规 MVC 控制器的 ASP.NET MVC Core 应用程序。此外,我们在 Controllers 文件夹中还有一个名为“API”的子文件夹,其中包含少量 API 控制器。
我们正在使用.IncludeXmlComments
内的方法.AddSwaggerGen
获取我们项目中的 XML 文档。
然而,它也为我们所有的常规控制器获取 XML。
有没有办法过滤掉“常规”控制器,或者仅选择 API 控制器包含在 swagger 文档中?
看一下文档包含谓词 https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/master/README.md#customize-the-action-selection-process,它应该可以解决你的问题????
// Startup.cs
services.AddSwaggerGen(options =>
options.DocInclusionPredicate((docName, apiDesc) =>
{
if (!apiDesc.TryGetMethodInfo(out MethodInfo methodInfo)) return false;
// Check if methodInfo is in the right assembly
// or has the right namespace or version etc.
bool isMethodIncluded = /* true or false */;
return isMethodIncluded ;
});
);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)