Amit Singh Rawat
Amit Singh Rawat

Reputation: 589

Nuget package"Swagger-Net" swagger-ui default ui page Modification In Asp.net mvc5

I am having a project in asp.net mvc5 and added swagger which Swagger-Net NuGet package (https://github.com/heldersepu/Swagger-Net)

enter image description here

and here I need to remove HTML section which is inside of red rectangle this is default UI provided by Swagger-Net

Upvotes: 1

Views: 348

Answers (1)

Chris.ZA
Chris.ZA

Reputation: 1286

You could either replace index.html with your own entirely or use CSS to hide the div.

To replace index.html, do something like this.

httpConfiguration
     .EnableSwagger(c => c.SingleApiVersion("v1", "A title for your API"))
     .EnableSwaggerUi(c =>
         {
             c.CustomAsset("index", yourAssembly, "YourWebApiProject.SwaggerExtensions.index.html");
         });

Replacing the entire index.html file may be a bit of an overkill for this and will mean you need to maintain this as Swagger updates it. So, if you wanted to just hide the block you could do that with CSS.

Specify a custom stylesheet like so:

httpConfiguration
    .EnableSwagger(c => c.SingleApiVersion("v1", "A title for your API"))
    .EnableSwaggerUi(c =>
        {
            c.InjectStylesheet(containingAssembly, "Swagger-Net.Dummy.SwaggerExtensions.testStyles1.css");
        });

and then in your custom stylesheet (testStyles1.css) put:

information-container { 
    display: none; 
}

See here for more information about both options.

Upvotes: 2

Related Questions