How to change swagger documentation base url?

For Java it looks like:

new Docket(DocumentationType.SWAGGER_2)
    .host("www.mydomain.com")
    .pathProvider(new RelativePathProvider(servletContext) {
        @Override
        public String getApplicationBasePath() {
            return "/myapi";
        }
   });

See how to change base path for swagger 2.0


You can use the below setting and get the swagger root url from the web config file:

.EnableSwagger(c =>
{                                                 
    c.RootUrl(req => GetRootUrlFromAppConfig());
})

The method - GetRootUrlFromAppConfig() should get the root url from the configuration.


Found another way to set a customURL, based on the request URI:

 config
    .EnableSwagger(c => {
        c.RootUrl(req =>
        {
            var url = req.RequestUri.Scheme + "://" + req.RequestUri.Authority + System.Web.VirtualPathUtility.ToAbsolute("~");
            return url;
        });