Right now I'm developing an ASP.Net Web API and using Swashbuckle for its documentation. I know that Swashbuckle use Swagger-UI internally, I know that we can modify the layout by injecting our css or javascript file, even change the layout of index.html.
I found a good themes for Swagger-UI https://github.com/jensoleg/swagger-ui and trying to implement it but can't make it works. Especially when I want to inject bootstrap.js. Is there anyway I can completely change Swashbuckle Swagger UI implementation so I can use the solution from that repo?
To replace logo in swagger in api for . net core, you have to add the custom. js file.
In addition to its Swagger 2.0 and OpenAPI 3.0 generator, Swashbuckle also provides an embedded version of the awesome swagger-ui that's powered by the generated Swagger JSON.
Swashbuckle is an open source project for generating Swagger documents for Web APIs that are built with ASP.NET Core. There are three core components: AspNetCore. SwaggerGen - provides the functionality to generate JSON Swagger documents that describe the objects, methods, return types, etc. AspNetCore.
Sure you can - in two steps.
1) Include file Index.html as Embedded resource in your assembly. For example let's say your web api project is named "Contosco.Api" and Index.html will be located under "/Content/Index.html" in this project.
2) Override swagger UI main html page with your own
[assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")]
public class SwaggerConfig
{
public static void Register()
{
var thisAssembly = typeof(SwaggerConfig).Assembly;
GlobalConfiguration.Configuration.EnableSwagger(c => {
// configure swagger
})
.EnableSwaggerUi(c => {
// beware - the Contosco.Api.Content.Index.html has to match your project paths :)
c.CustomAsset("index", thisAssembly, "Contosco.Api.Content.Index.html");
});
}
}
You just download .zip
folder, extract and include to your project.
In SwaggerConfigre.cs
you don't need configure any more.
Just put template into folder Swagger
and when you access {domain}/swagger
it will hit index.html
. (Don't need change Build action to Embedded Resource, Content is fine)
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