我正在使用swagger-ui为我们的客户提供REST API的良好文档.在内部,我们有两个不同的环境jenkin构建项目.例如,swagger.json可在以下两种环境中访问:
http://www.myhost.com/xyz/rest/swagger.json
https://www.myhost2.com/rest/swagger.json
文档可用:
http://www.myhost.com/xyz/dist/index.html
https://www.myhost2.com/dist/index.html
web.xml中的swagger api basepath是:
<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>/rest</param-value>
</init-param>
Run Code Online (Sandbox Code Playgroud)
问题:我正在尝试在文档页面上使用"试一试"功能.两台主机的相应请求URL如下:
http://www.myhost.com/rest/getAUser
https://www.myhost2.com/rest/getAUser
它适用于host2,因为它正在访问正确的URL.但它应该击中http://www.myhost.com/xyz/rest/getAUser
host1,但它正在击中网址http://www.myhost.com/rest/getAUser
.
有没有办法可以为不同的URL指定多个basepath.
我的swagger-ui html看起来像这样.
$(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",
......
......
}
Run Code Online (Sandbox Code Playgroud)