Reputation: 5216
We have an ASP.NET MVC Core application with regular MVC controllers. In addition, we have a subfolder within the Controllers folder called "API", containing a small number of API controllers.
We're using the .IncludeXmlComments
method within .AddSwaggerGen
to pick up the XML documentation within our project.
However, it's also picking up the XML for all our regular controllers too.
Is there a way to filter out the 'regular' controllers, or otherwise select only API controllers for inclusion in the swagger documentation?
Upvotes: 4
Views: 1505
Reputation: 972
Have a look at DocInclusionPredicate, it should solve your problem 😉
// 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 ;
});
);
Upvotes: 4