swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

RestEasy 3.x integration

Open ben-manes opened this issue 11 years ago • 26 comments

Due to Jersey2 not integrating cleanly with Guice, I'm using RestEasy 3.x for JAX-RS 2. The documentation only provides RestEasy 2.x and Jersey samples. I think that the Jersey2 module could be adapted, but I haven't looked into that yet.

ben-manes avatar Apr 21 '15 09:04 ben-manes

If you need JAX-RS 2 support with RESTEasy, use the swagger-jersey2-jaxrs module. The module adds support for jax-rs 2 and file uploads when using Jersey 2. It should work just as well for RESTEasy, only without the file upload support. If you require it, that can be resolved differently.

webron avatar Apr 21 '15 09:04 webron

Yep, that's what I'm experimenting with right now.

ben-manes avatar Apr 21 '15 09:04 ben-manes

@ben-manes - any updates?

webron avatar Apr 29 '15 11:04 webron

I only got as far as a the basics working before switching off to other tasks. What I had found was,

  • JerseyJaxrsConfig has to be replaced a ServletContextListener supplying a BeanConfig.
  • The DefaultJaxrsScanner isn't useful because there is no Application bounded, so a custom scanner is needed.

That custom scanner will either pull the classes from ResteasyProviderFactory or walking the Guice injector mimic'ing what ModuleProcessor does. I haven't tried writing it yet, so that's my next task.

I integrated Guice + Jersey 1.x + Swagger 1.x a few years ago and there was a lot of quirks at the time, so I imagine there will be some unexpected issues this time around too.

ben-manes avatar May 01 '15 07:05 ben-manes

It would be helpful if M2-SNAPSHOT was published as the BeanConfig in M1 does not support multiple resource packages.

ben-manes avatar May 01 '15 09:05 ben-manes

Okay, here's a gist that performs the integration. Feel free to adapt as you see fit.

It was easier to scan the Guice bindings than determine how to extract the resource classes from RestEasy's registry. Most likely the DefaultJaxrsScanner will work in a non-Guice setup.

ben-manes avatar May 01 '15 10:05 ben-manes

thanks @ben-manes. There is an m2-snapshot in sonatype, fyi.

fehguy avatar May 04 '15 04:05 fehguy

I found that there's 1.5.3-M1 on Maven Central, which has the changes needed to remove the ResourceConfig class. The pom on master would indicate that 1.5.1-M1 is the latest release, which is what I was using, so I'm not sure what the version history is.

ben-manes avatar May 04 '15 04:05 ben-manes

oh for shame. The snapshot wasn't pushed---I've just done it:

https://oss.sonatype.org/content/repositories/snapshots/com/wordnik/swagger-core/

Sorry about that.

fehguy avatar May 04 '15 04:05 fehguy

The version history on Maven Central is confusing if going by dates:

http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.wordnik%22%20AND%20a%3A%22swagger-project%22

It indicates that 1.5.1-M2 was released after 1.5.3-M1.

I had expected master to be a SNAPSHOT version so when looking at the code I had taken 1.5.1-M1 instead of looking at central, which caused me to pull an old BeanConfig class. I'm not sure what the release I should point to as the latest.

ben-manes avatar May 04 '15 04:05 ben-manes

master is stable, develop_2.0 is snapshot.

1.5.1-M2 is indeed newer than 1.5.3-M1.

webron avatar May 04 '15 06:05 webron

I'm also using resteasy 3 with guice 4 but my configuration is a bit simpler https://gist.github.com/natros/370c0093fa60379c3901

I'm missing file upload support.

natros avatar May 16 '15 15:05 natros

@natros - there's no file upload support for RESTEasy. You can easily add it on your own though by creating a SwaggerExtension. Check out https://github.com/swagger-api/swagger-core/pull/1023 for an example. Registering the SwaggerExtension is very simple as we use the standard SPI mechanism.

webron avatar May 16 '15 15:05 webron

@ben-manes - any updates?

webron avatar May 28 '15 15:05 webron

No, what additional information do you expect?

ben-manes avatar May 28 '15 17:05 ben-manes

You asked which release to try and were provided with the information.

webron avatar May 28 '15 17:05 webron

Sure, and I showed working code using a recent release. This works from my perspective.

ben-manes avatar May 28 '15 17:05 ben-manes

Thanks. I'll keep the issue open so that we may be able to provide easier integration in the future.

webron avatar May 28 '15 17:05 webron

@ben-manes Could you please add an example for the web.xml used? a full example would be really helpful.

laurentpellegrino avatar Jul 12 '15 18:07 laurentpellegrino

I didn't use a web.xml file because I prefer running Jetty as an embedded library, so everything is configured in Guice. Here's a gist of how that's done.

ben-manes avatar Jul 12 '15 18:07 ben-manes