Swagger (Swashbuckle) hide header

Unfortunately I think you can do it olny by javascript right now.

In your SwaggerConfig.cs you can inject a .js file like this:

.EnableSwaggerUi(c =>
{                        
    c.InjectJavaScript(thisAssembly, "yournamespace.yourscript.js");
});

So in this script you can do whatever you want, like hide the header:

document.querySelector("#header").style.display = "none";

This post shows how to customize the header putting two text boxes on it.

Edit:

The approach suggested in @dimaKudr's answer is better. Inject a CSS style is enough to hide the menu (JS is not necessary).


When I injected JS as suggested above, header was blinking at the page loading. It was shown for a second and then was disabled by script. There is approach that works better for me. https://github.com/domaindrivendev/Swashbuckle/issues/476

You can inject CSS instead of JS:

#header {
display:none;
}