我正在使用 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 基本路径是:
<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>/rest</param-value>
</init-param>
问题:
我正在尝试使用文档页面上的“试用”功能。
两个主机各自的请求url如下:http://www.myhost.com/rest/getAUser
https://www.myhost2.com/rest/getAUser
它适用于 host2,因为它访问了正确的 url。不过应该已经打到了http://www.myhost.com/xyz/rest/getAUser
对于 host1 但它正在访问 urlhttp://www.myhost.com/rest/getAUser
.
有没有办法可以为不同的网址指定多个基本路径。
我的 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",
......
......
}