erotavlas
erotavlas

Reputation: 4493

How do I use swagger-ui?

I'm using the Swashbuckle NuGet package in my web api project and I was trying to replace the default Swagger UI with this one https://github.com/jensoleg/swagger-ui

but I keep getting this error message

<?xml version="1.0" encoding="ISO-8859-1"?>
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>Embedded resource not found - ReportsAPI.swagger-ui.Index.html</ExceptionMessage>
<ExceptionType>Swashbuckle.SwaggerUi.AssetNotFound</ExceptionType>
<StackTrace> at Swashbuckle.SwaggerUi.EmbeddedAssetProvider.GetEmbeddedResourceStreamFor(EmbeddedAssetDescriptor resourceDescriptor, String rootUrl) at Swashbuckle.SwaggerUi.EmbeddedAssetProvider.GetAsset(String rootUrl, String path) at Swashbuckle.Application.SwaggerUiHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)</StackTrace>
</Error>

I followed the advice from this post Replace Swashbuckle UI completely

But was unable to get it to work

I have a basic ASP.Net Web API 2 (simple rest api with no website or index html)

So I downloaded the zip file from the GitHub page of swagger-ui and copied the dist folder to my project and included it as (tried both Content and Embedded resource) - and renamed dist folder to swagger-ui

So my root project folder now looks like

enter image description here

Then I changed my Swagger config to add the following

c.CustomAsset("index", thisAssembly, "ReportsAPI.swagger-ui.Index.html");

Is that correct? I'm not sure where to go from here

Do I have to include all other files as Embedded resource? Or just the Index.html? What do I mark the other files as, Content? Copy always?

Upvotes: 0

Views: 1118

Answers (1)

Helder Sepulveda
Helder Sepulveda

Reputation: 17664

Here is an alternative that does not require you to embed anything into your project:

https://raw.githack.com/jensoleg/swagger-ui/master/dist/index.html?url=https://swagger-net-test.azurewebsites.net/swagger/docs/V1

As you can see my swagger spec is provided with in the url parameter.
You could use that raw.githack.com or just copy the dist folder to a more convenient location.


Now I would like to point out that is a very old version of swagger-ui and does not look to be well maintained, maybe you should take a look at: ReDoc https://github.com/Rebilly/ReDoc/blob/master/README.md

Upvotes: 1

Related Questions