It still renders the built-in index.html and refuses to recognize my custom files.
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Looks like the whole section is outdated. I was able to get the custom CSS work based on this:
https://github.com/domaindrivendev/Swashbuckle.AspNetCore#inject-custom-css
Instructions on how to customize index.html
are available on the same page.
My Startup.cs
looks like this:
``` C#
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseStaticFiles();
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
c.RoutePrefix = string.Empty;
c.InjectStylesheet("/swagger-ui/custom.css");
});
// ...
}
And I created a file `wwwroot\swagger-ui\custom.css` with the following contents:
``` CSS
.swagger-ui .topbar {
background-color: #000;
border-bottom: 3px solid #547f00;
}
@mattacks and @TurboLion, I did manage to get this to work as documented, but it took me a while to realize this is the important part:
Browse to the index.html page at
http://localhost:<port>/swagger/ui/index.html
. Enterhttp://localhost:<port>/swagger/v1/swagger.json
in the header's textbox, and click the Explore button. The resulting page looks as follows:
Most especially the part that this is a new URL. Note the /ui/
portion so it's no longer the default URL.
To make it a bit simpler (for me), I modified the index.html
to default to my own JSON file:
// Build a system
const ui = SwaggerUIBundle({
//url: "https://petstore.swagger.io/v2/swagger.json", // comment this out
url: "/swagger/v1/swagger.json", // this the default swagger doc
Oh, and if you want the dropdown for the API choices at the top, you can modify the index.html
again:
// remove this from the dist version of index.html
//url: "https://petstore.swagger.io/v2/swagger.json",
// this becomes the dropdown choices
urls: [
{
url: "/swagger/v1/swagger.json",
name: "My API V1"
}
],
Thanks for contacting us.
We don’t have the resources to invest in this area, so we are closing the issue. Should your request generate enough 👍 responses, we’ll reconsider.
Most helpful comment
Looks like the whole section is outdated. I was able to get the custom CSS work based on this:
https://github.com/domaindrivendev/Swashbuckle.AspNetCore#inject-custom-css
Instructions on how to customize
index.html
are available on the same page.My
Startup.cs
looks like this:``` C#
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseStaticFiles();
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
c.RoutePrefix = string.Empty;
c.InjectStylesheet("/swagger-ui/custom.css");
});
}