Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger (Swashbuckle) hide header

I use Swashbuckle to add Swagger documentation to my ASP.NET Web API project. How can I hide default header (with swagger logo) from documentation page without injecting CSS?

like image 437
ranquild Avatar asked Jul 26 '15 12:07

ranquild


2 Answers

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;
}
like image 166
dimaKudr Avatar answered Nov 06 '22 23:11

dimaKudr


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).

like image 10
fabriciorissetto Avatar answered Nov 07 '22 00:11

fabriciorissetto