StarCub
StarCub

Reputation: 4341

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?

Upvotes: 2

Views: 5677

Answers (1)

quotschmacher
quotschmacher

Reputation: 69

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

Upvotes: 2

Related Questions