Skip to content

Can't get Swagger + Servlet to work. My APIs are not listed. #463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
HelenGao opened this issue Feb 13, 2014 · 15 comments
Closed

Can't get Swagger + Servlet to work. My APIs are not listed. #463

HelenGao opened this issue Feb 13, 2014 · 15 comments

Comments

@HelenGao
Copy link

Hi.
I followed Swagger Servlet Quickstart guide, and expected to see MyRESTServlet listed under https://localhost:8443/myServer/api-docs. But all it displays is {"apiVersion":"1.0.0","swaggerVersion":"1.2"}.

I annotated my HttpServlet as below:
@Api(value = "/myPath", description = "My REST servlet!")
public class MyRESTServlet extends HttpServlet
{

I added two Swagger servlets in my Tomcat web.xml as instructed by Swagger as below, but not sure if I am supposed to make any changes. For example, what does the paramter swagger.api.basepath means when it's set to http://localhost:8002?

Here is what the Swagger instruction says https://github.com/wordnik/swagger-core/wiki/Servlet-Quickstart: Swagger scans all classes with an @Api annotation on them. Each @Api resource will appear as an Api Declaration in swagger. The annotation is done as follows:

import com.wordnik.swagger.annotations.*;
@Api(value = "/sample/users", description = "gets some data from a servlet")
public class SampleServlet extends HttpServlet {
...
Swagger will list your api under /sample/users as well with the description specified.

I am not sure if this is the right venue for this type of question. Thank you in advance.

@rage-shadowman
Copy link

If you are using the reflection scanner, you might need to add a dependency on the reflections api v0.9.9-RC1.

For maven:

         <dependency>
            <groupId>org.reflections</groupId>
            <artifactId>reflections</artifactId>
            <version>0.9.9-RC1</version>
         </dependency>

The version before this (included with swagger-core) is broken and cannot handle the vfs urls that are returned by JBoss. Perhaps Tomcat returns the same vfs style urls when Swagger tries to get the package to scan.

@HelenGao
Copy link
Author

Hi Shodow Man, 

Thanks. A Reflection jar has been deployed. There is no error when I built my project or when Tomcat ran. Just Swagger is not showing my APIs.

On Thursday, February 13, 2014 6:28 PM, Shadow Man [email protected] wrote:

If you are using the reflection scanner, you might need to add a dependency on the reflections api v0.9.9-RC1.
For maven:
org.reflections reflections 0.9.9-RC1
The version before this (included with swagger-core) is broken and cannot handle the vfs urls that are returned by JBoss. Perhaps Tomcat returns the same vfs style urls when Swagger tries to get the package to scan.

Reply to this email directly or view it on GitHub.

@rage-shadowman
Copy link

@HelenGao Yes, that is exactly what I would expect to see if the incorrect reflection jar was included. See #412

@webron
Copy link
Contributor

webron commented Feb 14, 2014

@HelenGao, I think we should continue this discussion in the google group (since you left a message there as well). If we'll find an actual issue, you're more than welcome to open a new one.

@webron webron closed this as completed Feb 14, 2014
@poonkothai408425
Copy link

I am facing the same issue.

I used java jersey swagger.API is not listing.

can any one provide solution for java jaxrs swagger?

@webron
Copy link
Contributor

webron commented Feb 21, 2014

Can you provide a few more details? What have you done so far?

On Fri, Feb 21, 2014 at 1:38 PM, poonkothai408425
[email protected]:

I am facing the same issue.

I used java jersey swagger.API is not listing.

can any one provide solution for java jaxrs swagger?


Reply to this email directly or view it on GitHubhttps://github.com//issues/463#issuecomment-35723522
.

@HelenGao
Copy link
Author

Hi Shadow man and webon,

Thanks a lot for your help. But I still can't get Swagger + Servlet to work. My APIs are still not listed. https://localhost:8443/MyServer/api-docs only displays {"apiVersion":"1.0.0","swaggerVersion":"1.2"}. I am not sure if the conflict of jar files below is the reason.

I downloaded and built scala-servlet, then copied all jars from scala-servlet\target\lib to my Tomcat webapps\MyServer\WEB-INF\lib. One of the files I copied was servlet-api-2.5.jar. But Tomcat couldn't load this jar because a similar file already exist. The existing jar is servelt-api.jar from Tomcat 7. The error message is below.

catalina log - INFO: validateJarFile(C:\Eclipse\Slingshot Trunk\server\webapps\vault\WEB-INF\lib\servlet-api-2.5.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

Your input would be much appreciated.

Helen

@webron
Copy link
Contributor

webron commented Mar 23, 2014

@HelenGao - I believe Tony is helping you work this out in the mailing list. Can I close the issue here?

@HelenGao
Copy link
Author

Sure. Thanks.

On Sunday, March 23, 2014 4:51 AM, webron [email protected] wrote:

@HelenGao - I believe Tony is helping you work this out in the mailing list. Can I close the issue here?

Reply to this email directly or view it on GitHub.

@tokra
Copy link

tokra commented Oct 7, 2015

Hello I have issue using reflections ClasspathHelper.forPackage for scan -> on local WLP it works fine but deployed on WAS it returns zero results... Anyone help ?

@webron
Copy link
Contributor

webron commented Oct 7, 2015

@to-kra - can you open a new issue or even just send the question to the google group. It'd be difficult to track this way.

@tokra
Copy link

tokra commented Oct 7, 2015

@webron I found a problem in BeanConfig, which scans classes by package. Reflections ClassHelper.forPackage(..) does not count with possibility that classes can be inside of jars like in WEB-INF/lib, as our deployed app has modules compiled into jars placed into WEB-INF/lib. I extended BeanConfig and changed method classes() where i do also fallback to ClasspathHelper.forWebInfLib(..) which can find such jar-ed classes. Now everything works fine !

@webron
Copy link
Contributor

webron commented Oct 7, 2015

@to-kra - great, thanks for the update!

@JathinSanghvi
Copy link

Facing similar issue as @HelenGao. Can you share what was the solution for it. or atleast a link to mailing thread.

@ghost
Copy link

ghost commented Sep 7, 2016

@to-kra
I am facing same issue.
Could you please explain me your solution in details or share code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants