Hello,
my company's application is split into different services (Maven subprojects) uses swagger 2.2.0 and unpacks the swagger-ui during prepare-package phase. We use a SwaggerBootstrap.java that configures some of parts of Swagger:
@WebServlet(loadOnStartup = 1)
public class SwaggerBootstrap extends HttpServlet {
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
BeanConfig beanConfig = new BeanConfig();
beanConfig.setVersion("1.0.0");
beanConfig.setSchemes(new String[]{"http"});
String contextPath = config.getServletContext().getContextPath();
ApplicationPath applicationPath = JaxRsActivator.class.getAnnotation(ApplicationPath.class);
beanConfig.setBasePath(contextPath + "/" + applicationPath.value());
beanConfig.setResourcePackage(this.getClass().getPackage().getName());
beanConfig.setScan(true);
beanConfig.setPrettyPrint(true);
}
}
JaxRsActivator has an ApplicationPath set to "api". So when I deploy the article-service on Wildfly (without Swarm) I can access Swagger UI via: localhost:8080/article-service/api. But when doing the same with Wildfly Swarm the context path is set to / by default. So I tried to calling the Swagger UI via locahost:8080/ which works, kind of. But I noticed that the "BASE URL" at the bottom has no value and no version is shown.
Then I checked the JavaScript console and checked the value of window.swaggerUi.api.basePath which has the value of "". For the non Wildfly Swarm deployment it is set to /article-service/api. Also the routes for the api calls are wrong. It has no /api prefix before the get call.
I am not sure why this happens. I also set the context path to /article-service via Wildfly Swarm's project-defaults.yml. I now have to call it via localhost:8080/article-service, but the problem is the same.
How does swagger ui set it's baseUrl and is there a way to change it?