Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify https scheme in Swashbuckle for .NET Core

How can I specify https schema in the .NET Core version of Swashbuckle? In ASP.NET version I could do

.EnableSwagger(c =>
{
  c.Schemes(new[] { "https" });
}

but I don't see anything similar as part of AddSwaggerGen.

like image 632
SiberianGuy Avatar asked Feb 01 '17 06:02

SiberianGuy


1 Answers

Just implement the interface IDocumentFilter and use it in Startup.cs:

public class TestFilter : IDocumentFilter
{
    public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context)
    {
        swaggerDoc.Schemes = new string[] { "http" };
    }
}

// Startup.cs
services.AddSwaggerGen(c =>
{
     c.SwaggerDoc("v2", new Swashbuckle.AspNetCore.Swagger.Info 
                        { Title = "My API", Version = "v2" });
     c.DocumentFilter<TestFilter>();
 });
like image 162
mhofer4991 Avatar answered Nov 07 '22 11:11

mhofer4991