baseUrl not set when using swagger-ui with Wildfly Swarm

533 views
Skip to first unread message

Christian

unread,
Jan 4, 2018, 5:34:56 AM1/4/18
to Swagger
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?

Christian

unread,
Jan 4, 2018, 5:42:19 AM1/4/18
to Swagger
I should mention that swagger-jaxrs is a dependency which is has the scope "provided", since Wildfly Swarm detects swagger and adds it when running the package stage.

<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<version>${version.swagger}</version>
<scope>provided</scope>
</dependency>

I am not sure if this is the issue. But it will fail when I remove the scope tag.

Christian

unread,
Jan 4, 2018, 6:10:02 AM1/4/18
to Swagger
I have found the solution. I did not add an additional main method nor did I add a swarm.swagger.conf. With the latter one it works.


Am Donnerstag, 4. Januar 2018 11:34:56 UTC+1 schrieb Christian:
Reply all
Reply to author
Forward
0 new messages