0

I am using .NET Core WebAPI (Nswag) I wanted to hide below items from swagger UI. Is that possible?

  1. 'Select Definition' and dropdown (Top right corner)
  2. BaseURL and Swagger.json link
  3. Schemes and dropdown.

Highlighted in below screenshot.

enter image description here

Sathish
  • 159
  • 1
  • 4
  • 18

1 Answers1

1

You can add your own custom CSS and use it to hide those elements (and do any other customisation you want).

Create a wwwroot/swagger-ui folder in the root of your project, and add custom.css to it:

.swagger-ui .topbar .download-url-wrapper {
    display: none;
}

.swagger-ui .info hgroup.main a {
    display: none;
}

.swagger-ui section.models {
    display: none;
}

And in Program.cs (Startup.cs in .Net5):

app.UseSwaggerUI(c =>
    {
        c.InjectStylesheet("/swagger-ui/custom.css");
    });

Don't forget app.UseStaticFiles();.

Result:

enter image description here

Is this what you want?

Update:

NSwag can also customize CSS styles:

custom.css:

.swagger-ui .topbar .download-url-wrapper {
    display : none;
}

.swagger-ui .info .base-url {
    display : none;
}

.swagger-ui .info hgroup.main a {
    display: none;
}

.swagger-ui .scheme-container {
    display : none;
}

And in Program.cs (Startup.cs in .Net5):

app.UseSwaggerUi3(c => {
        c.CustomStylesheetPath = "/swagger-ui/custom.css";
    });

Don't forget app.UseStaticFiles();.

Result: enter image description here

Chen
  • 4,499
  • 1
  • 2
  • 9