Search code examples
swaggerswagger-uiswashbuckle

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?


Solution

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