Aspnetcore.docs: Swashbuckle Asp.Net core section 'Customize the UI' instructions do not work

Created on 29 May 2018  ·  3Comments  ·  Source: dotnet/AspNetCore.Docs

It still renders the built-in index.html and refuses to recognize my custom files.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

P3 Source - Docs.ms

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");
});

// ...

}

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;
}

All 3 comments

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. Enter http://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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

madelson picture madelson  ·  3Comments

nenmyx picture nenmyx  ·  3Comments

serpent5 picture serpent5  ·  3Comments

Rick-Anderson picture Rick-Anderson  ·  3Comments

StevenTCramer picture StevenTCramer  ·  3Comments