Swagger-UI and OpenApiFeature plugin

I find the version of Swagger-UI that ships with ServiceStack (6.11 or earlier) to be hopelessly slow with larger API’s. I’ve experimented with the latest Swagger-UI and it’s at least 100 times faster on the intial load compared to the current version ServiceStack uses.

So, I’ve embarked on an effort to see what I need to do to use the latest Swagger-UI.

I’ve been reading the docs on replacing the built-in ServiceStack embedded resources relating to Swagger-UI on Open API

If I put the latest Swagger-UI files in a swagger-ui folder, when clicking the Swagger-UI link on the metadata page the OpenAPIFeature adds does use the new Swagger-UI - but it’s not setting the URL for the openapi document to be the /openapi of the API.

I’ve tried a few things like editing the swagger-initializer.js as per the swagger-ui docs, but nothing seems to work - it still is the http://petstore.swagger.io/v2/swagger.json default.

The OpenApiFeature plugin must be weaving some magic to set that URL, but I can’t see where when looking in ServiceStack/src/ServiceStack.Api.OpenApi/OpenApiFeature.cs.

Is there a simple way to use the latest Swagger-UI?

Not sure about magic, but it just replaces the hard coded URL in the static index.html with /openapi at:

But since it’s a completely different UI I wouldn’t consider trying to replace it over the existing OpenApiFeature.

Instead I’d take a copy of the ServiceStack.Api.OpenApi, rename it to something like OpenApi3 that completely replaces the old UI with the new UI.

I have no idea why I didn’t properly parse that! I saw the petstore URL and did not cognitively process the fact it was performing a .Replace() of the html document.

Thanks

1 Like