Swagger does not support two rest services in one web.xml
See original GitHub issueI have implemented two rest services with jersey, they are in different packages. I want to deploy them in one web.xml but I am expecting I can get two separate swagger.json(s) by visiting different path: http://localhost:8080/mywebapp/service1/swagger.json http://localhost:8080/mywebapp/service2/swagger.json
but actually, I could not get what I need, the result is, each first time I open one of the above url after the my web container(Jetty here) is start up I can get the right swagger.json doc, but the second time no matter which paths i visit, i will keep getting the doc that I first time visit.
if you could not understand the case, let me give an example: see below part of my web.xml
<servlet>
<display-name>servlet1</display-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.test.rest.service1; io.swagger.jaxrs.listing</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>servlet1</servlet-name>
<url-pattern>/service1/*</url-pattern>
</servlet-mapping>
<servlet>
<display-name>servlet2</display-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.test.rest.service2; io.swagger.jaxrs.listing</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>servlet2</servlet-name>
<url-pattern>/service2/*</url-pattern>
</servlet-mapping>
I can run the application in my local Jetty then I open path http://localhost:8080/mywebapp/service1/swagger.json and I can get the api doc successfully, But when I try to get the api doc for my another service by visiting http://localhost:8080/mywebapp/service2/swagger.json, I am not getting the api doc for service2, instead, I am keep getting the api doc for service1, even though I have set the path to service2.
if there a way that can make two rest services running in one container, and able to generate two separate swagger api docs by visiting different path?
Thanks
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (1 by maintainers)
If you want to do this without a
web.xml
file, you could just create 2 Swagger web-services like this one: https://github.com/Coreoz/Plume-archetypes/blob/master/plume-archetype-querydsl-jersey-guice/src/main/resources/archetype-resources/src/main/java/webservices/internal/SwaggerWs.javaI am facing something same issue.I have two servlet configure as folloeing: http://localhost:8080/mywebapp/rest/swagger.json for this Rest service call URL is http://localhost:8080/mywebapp/rest/for/firmName/getMessage http://localhost:8080/mywebapp/restservice/swagger.json for this Rest service call URL is http://localhost:8080/mywebapp/restservice/firmName/getMessage2
I have configured this by declaring two beanconfing.But facing same issue as stated in orginal issue. Could you please help me in this issue.