'Different DocInclusionPredicate for different swagger document with Swashbuckle.AspNetCore

I'm trying to generate multiple swagger.json documents and using Customize the Action Selection Process to determine which action goes to which swagger document.

Is it possible to have different DocInclusionPredicate for different swagger document?

For example, I have

services.AddSwaggerGen(c =>
{
    c.SwaggerDoc("v1", new Info { Title = "My API - V1", Version = "v1" });
    c.SwaggerDoc("v2", new Info { Title = "My API - V2", Version = "v2" });
})

How do I specify one DocInclusionPredicate for v1 and another DocInclusionPredicate for v2 document?



Solution 1:[1]

c.DocInclusionPredicate((docName, apiDesc) =>
{
    if (docName == "v1")
    { /* actions for v1 */ }
    else if (docName == "v2")
    { /* actions for v2 */ }
});

and then return true if the predicate belongs to the specific version or false if it shall be filetered out in the correct if-statement

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 quotschmacher