I am using swagger-ui to provide nice documentation for REST APIs to our clients.
Internally we have two different environments jenkin builds the project to.
E.g. swagger.json is accessible on both environment as:
http://www.myhost.com/xyz/rest/swagger.json
https://www.myhost2.com/rest/swagger.json
Documentation is available as:
http://www.myhost.com/xyz/dist/index.html
https://www.myhost2.com/dist/index.html
swagger api basepath in web.xml is:
<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>/rest</param-value>
</init-param>
ISSUE:
I am trying to use "Try it out" feature on documentation page.
The respective request url for both hosts are as follows:
http://www.myhost.com/rest/getAUser
https://www.myhost2.com/rest/getAUser
It works for host2 as it is hitting the correct url. However it should have hit http://www.myhost.com/xyz/rest/getAUser
for host1 but it is hitting the url http://www.myhost.com/rest/getAUser
.
Is there a way I can specify multiple basepath for different urls.
My swagger-ui html looks something like this.
$(function () {
var href = window.location.href;
var url = href.substring(0, href.lastIndexOf("/dist"));
console.log(url);
// Pre load translate...
if(window.SwaggerTranslator) {
window.SwaggerTranslator.translate();
}
window.swaggerUi = new SwaggerUi({
url: url + "/rest/swagger.json",
dom_id: "swagger-ui-container",
......
......
}