How does swagger block the interface that comes with it by default?

as shown in the figure below, a Swagger interface is always generated by default after swagger documents are generated. After a careful study of the configuration file, there is no option to block this interface.

this interface is useless. Putting it here will affect the outlook. How to block this interface?

May.22,2021

1. Add DocumentFilter to the SwaggerConfig.cs file

GlobalConfiguration.Configuration.EnableSwagger(c =>{
    //  DocumentFilter
    c.DocumentFilter<HiddenApiFilter>();  
})

2. Add HiddenApiFilter.cs class

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]   
public partial class HiddenApiAttribute : Attribute { }
public class HiddenApiFilter : IDocumentFilter
{
   
    public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer)
    {
        foreach (ApiDescription apiDescription in apiExplorer.ApiDescriptions)
        {            
            var _key = "/" + apiDescription.RelativePath.TrimEnd('/');
            //  swagger 
            if (_key.Contains("/api/Swagger") && swaggerDoc.paths.ContainsKey(_key))
                swaggerDoc.paths.Remove(_key);
        }
    }
}

Menu