swagger-api / swagger-core

Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API
http://swagger.io
Apache License 2.0
7.36k stars 2.17k forks source link

Swagger and Jersey 2/Jax-RS 2, problem in UriBuilder #328

Closed joscarsson closed 10 years ago

joscarsson commented 10 years ago

I followed the guide at https://github.com/wordnik/swagger-core/wiki/Java-JAXRS-Quickstart to setup swagger for a Jersey 2/Jax-RS 2 project. However, as soon as I add the dependency to "com.wordnik:swagger-project_2.10:1.3.0" (gradle dependency format line) I get a 500 error when trying to access my normal API resources. The error given is: "java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;".

I found a jersey2 module for swagger in the 1.3.0-RC3 tag, but not in the 1.3.0 release tag, figured they had been merged into one. Is JAX-RS 2.0 supported?

fehguy commented 10 years ago

Hi, to use Jersey 2, you will need to use the 1.3.1-SNAPSHOT built specifically for that version of jersey:

https://oss.sonatype.org/content/repositories/snapshots/com/wordnik/swagger-jersey2-jaxrs_2.10/

joscarsson commented 10 years ago

Thank you, I got something up and running using the snapshot. However, it still does not show my annotated resources when accessing /api-docs/, but that might be another problem. Do I need to do something in order to get Swagger to scan the resources?

fehguy commented 10 years ago

You're probably missing one step--take a look here:

https://github.com/wordnik/swagger-core/wiki/Java-JAXRS-Quickstart#specify-a-swagger-configuration-class

joscarsson commented 10 years ago

You are absolutely right, thank you.

Floresj4 commented 10 years ago

I'm getting a missing artifact error with the dependency

com.wordnik swagger-jersey2-jaxrs_2.10 1.3.1-SNAPSHOT

What's up?

fehguy commented 10 years ago

Since this is in snapshot, you'll need to add sonatype snapshots to your pom.xml repository:

  <repositories>
    <repository>
      <id>sonatype-snapshots</id>
      <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
  </repositories>
Floresj4 commented 10 years ago

Problem solved. Great, thanks!! When will swagger start to support Jersey 2+

widarlein commented 10 years ago

Hi! I am trying to get swagger to work with jersey 2.4 with spring extension. I followed these instructions https://github.com/wordnik/swagger-core/wiki/Java-JAXRS-Quickstart but with the swagger-jersey2-jaxrs_2.10 1.3.1-SNAPSHOT instead. I have tried to use the sonata-snapshots repository as well as cloning the develop branch and installing the swagger-jersey2-jaxrs module in my local repo.

Also I noticed that a java-jersey2 sample was added a few days ago, but if I'm not missing something, it's using Jersey 1.3 as well since the web.xml uses "com.sun.jersey.spi.container.servlet.ServletContainer" as servlet-class instead of "org.glassfish.jersey.servlet.ServletContainer"

So, any idea why swagger just does not seem to engage?

cfergus commented 10 years ago

@widarlein - to augment your comment: I am doing the same. I tried checking out the module, and following : https://github.com/wordnik/swagger-core/tree/master/samples/java-jersey2 . I had to walk the version up to 1.3.1 for the dependencies and parent, but the build fails with an error in ResourceListingIT. Additionally, http://localhost:8002/api/api-docs.json responds with

<apiResponse>
  <message>
  null for uri: http://localhost:8002/api/api-docs.json
  </message>
  <type>unknown</type>
</apiResponse>

Ultimately, I was able to get things working, but the major hangup for me was that package scanning for the wordnik resources in my app didn't work; I had to explicitly register the individual resources register( ApiListingResourceJSON.class ); register( JerseyApiDeclarationProvider.class ); register( JerseyResourceListingProvider.class );