我使用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>
问题:我正在尝试在文档页面上使用"Try it out"功能 . 两台主机的相应请求URL如下: http://www.myhost.com/rest/getAUser https://www.myhost2.com/rest/getAUser
它适用于host2,因为它正在访问正确的URL . 但它应该为host1命中 http://www.myhost.com/xyz/rest/getAUser
但是它正在击中网址 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",
......
......
}
1 回答
我能够通过使用BeanConfig配置swagger而不是在web.xml中使用Servlet来解决此问题
BeanConfig类:
并在web.xml中:
我改变了我的pom.xml以开始使用最新稳定版本的swagger-jersey2-jaxrs: