question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Swagger does not support two rest services in one web.xml

See original GitHub issue

I 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:closed
  • Created 8 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
amanteauxcommented, Oct 16, 2016
0reactions
ghostcommented, Mar 27, 2017

I 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

can we move some swagger configuration from web.xml
Basically, in Swagger 1.3, you need to use the SwaggerConfig class, like so: SwaggerConfig config = new SwaggerConfig(); config.setBasePath(yourBasePathVariable); ...
Read more >
Setting Up Swagger 2 with a Spring REST API - Baeldung
In this tutorial, we'll look at Swagger 2 for a Spring REST web service, using the Springfox implementation of the Swagger 2 specification....
Read more >
Representing XML - Swagger
In your API specification, you can describe data in both XML and JSON formats as they are easily interchangeable. For example, the following...
Read more >
Web on Servlet Stack - Spring
The two main HandlerMapping implementations are RequestMappingHandlerMapping (which supports @RequestMapping annotated methods) and SimpleUrlHandlerMapping ( ...
Read more >
Top REST API Interview Questions and Answers (2022)
1. What do you understand by RESTful Web Services? ... REST supports data of multiple formats like XML, JSON, MIME, Text, etc.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found