I'm trying to customize swagger UI on my ASP.NET Core Web API.
I want the UI like this:
I'm following these tutorials:
This is the Startup.cs configuration:
// Add the detail information for the API.
services.ConfigureSwaggerGen(options =>
{
// Determine base path for the application.
var basePath = _env.WebRootPath;
// Complete path
var xmlPath = Path.Combine(basePath, "myapi.xml");
// Set the comments path for the swagger json and ui.
options.IncludeXmlComments(xmlPath);
});
app.UseStaticFiles();
// Enable middleware to serve generated Swagger as a JSON endpoint
app.UseSwagger();
// Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.)
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "MyAPI");
});
I already downloaded swagger ui files from the git repository and put on my project like this:
I don't know if this is the right thing to do, but I'm not able to see any changes to the swagger UI.
The tutorial you are following is using: Swashbuckle.AspNetCore unfortunately in that project they still using the Swagger-UI version 2.x, your Screenshot shows version 3.x
There are a few Pull Requests to update to latest Swagger-UI:
But unfortunately there is not much progress towards merging those.
I see that you know how to download files from a git repository...
My recommendation:
Instead of downloading the swagger-ui files, download the entire project Swashbuckle.AspNetCore from a fork that is using the version you need (such as: alexvaluyskiy/Swashbuckle.AspNetCore), then in your project add a reference to that project instead of the nuget package.
Another option could be creating your own fork of Swashbuckle.AspNetCore merge the fixes you need and then publish your own Nuget package with a different name.
I ran into a similar issue, and I needed to inject my style sheet:
c.InjectStylesheet("/Swagger/Ui/custom.css")
This was added to app.UseSwaggerUI
in the Startup.cs file.
The following articles helped, but I had to merge information from both to find my answer:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With