Jezz Santos - 274 - May 7, 2014

More Swagger Customization

Can we alter the default URL of the swagger plugin to be something like: /api/docs
instead of the default: /api/swagger-ui ??

Can it be done? What do I have to change apart from the default directory?

Not really it’s hard-coded into SwaggerFeature

The name is required because the underlying directory is named swagger-ui/. 

One approach is to redirect redirect /docs to /swagger-ui, e.g:

this.RawHttpHandlers.Add(httpReq => 
   return httpReq.PathInfo == “/docs”
      ? new RedirectHttpHandler {
            RelativeUrl = "/swagger-ui }
      : null;

Jezz Santos:

OK, do you reckon I could create my own variant of SwaggerFeature() class and change what is hardcoded there? Or might there be other stuff scattered elsewhere in the code do you think?

If you want, you can bundle the swagger assets as part of your app and rename the directory to /docs.

You’d also need to copy the Swagger Classes in:
and just rename swagger-ui to docs.

Jezz Santos:

Thanks. found a slightly different way of doing it, by creating my own IPlugIn, passing in the SwaggerFeature, and replacing the Metadata registration and requesthandler to do what I needed. Seems to be sustainable for now.