We are running two separate Jersey APIs in the same server context, il.e. two separate classes extending com.sun.jersey.api.core.PackagesResourceConfig are configured in Tomcat 7's web.xml to be two accessible under two separate base paths. Simplified it's:
<servlet>
<servlet-name>Api1</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>api1.server.config.Api1ServerConfig</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Api1</servlet-name>
<url-pattern>/api1/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Api2</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>api2.server.config.Api2ServerConfig</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Api2</servlet-name>
<url-pattern>/api2/*</url-pattern>
</servlet-mapping>
The two APIs do not share any model classes or other code and are completely separate in every aspect incl security, filter chains etc.
There are two separate application.wadl files (and their corresponding XSD schema) generated by Jersey, each describing only the resources from their respective API.
We are using swagger in the first API, configuring it using BeanConfig:
BeanConfig bc = new BeanConfig();
bc.setVersion("1.0");
bc.setTitle(" API1 Documentation");
bc.setSchemes(new String[]{"https"});
bc.setBasePath("/appRoot/api1");
bc.setResourcePackage("api1.resource");
bc.setScan(true);
Now we try to add Swagger to the second API as well, by declaring this in our Api2ServerConfig:
BeanConfig bc = new BeanConfig();
bc.setVersion("1.0");
bc.setTitle(" API2 Documentation");
bc.setSchemes(new String[]{"https"});
bc.setBasePath("/appRoot/api2");
bc.setResourcePackage("api2.resource");
bc.setScan(true);
Unfortunately while this results in two separate swagger.json documents under
/appRot/api1/swagger.json and /appRoot/api2/swagger.json, the two APIs are not treated separately as we had hoped.
The contents of whichever swagger document we access first after starting the server are fine. If we access /appRoot/api1/swagger.json, it contains all the paths and types of API1 and nothing from API2's realm. If however we next access /appRoot/api2/swagger.json, it lists both its own resources AND every tag, path and type definition from API1. Vice versa, if /appRoot/api2/swagger.json is accessed first and then appRoot/api1/swagger.json, API2's document is correct, but itself is now leaking into API1's swagger.json. The title and basePath are correct in both documents.
Is there anything else that needs to be done to keep multiple APIs from mixing, or is it just not possible at all?
I'm faced with the same problem usecase. Configuring through web.xml or BeanConfig in separate apps I can't find a way around it. It seems to be the same as https://github.com/swagger-api/swagger-core/issues/949 filed and closed against 1.3 due to lack of activity.
I also have same problem
ditto. Same Issue. I am running using the BeanConfig approach. Any word on a fix?
I'm also looking for the same. Setting up multiple packages with the same BeanConfig. Is there support for this? @fehguy Thanks!
Looking at BeanConfig, it looks like you can have multiple packages, separated by ,. Can you please try that?
I'm also facing the same issue. Any plans for the fix?
@dheerajarora which issue are you having? The original issue about scanning or multiple packages via beanConfig?
Since this issue has strayed, i'm closing. Please reopen a new one with details on the issue you're having.
thanks @fehguy, comma works.
The Problem that is described in the first comment from andi-livn is still not solved.
Should I open a new Ticket?
Most helpful comment
The Problem that is described in the first comment from andi-livn is still not solved.
Should I open a new Ticket?