Errors when implementing swagger in GRails with JAX-RS

667 views
Skip to first unread message

Scott Ryan

unread,
Nov 7, 2012, 4:41:32 PM11/7/12
to swagger-sw...@googlegroups.com
I have some services that are implemented in jax-rs within grails and i am having some challenges getting swagger to work properly.  My services are defined as follows:

@Path('/api/1.0.0/event')
@Api(value = "/api/1.0.0/event", description = "Operations about Event")
@Consumes(['application/json'])
@Produces(['application/json'])

My Jersey path is

/api
/api/**

I have defined the swagger config as:

'swagger.api.basepath':'http://localhost:8080/amp/api/1.0.0','api.version':"1.0"

I access the service via the url   http://localhost:8080/amp/api/1.0.0/event

I do not use the .json ending to my service names

When i deploy I initially get an error that

SEVERE: Producing media type conflict.

And this occurs on my GET method.  If I comment out the GET method the error goes away.   

I also cannot access the resources.json at any combination of the URLS

So my questions are:

1. How to I access my service with out the .json extension and still get Swagger to work
2. How do I deal with my media type conflict error
3. Where do I go to in order to access the resources.json file

If I comment out my GET method and use the .json ending to my service url I get some valid documentation.


Here are the versions I am using

runtime ("com.wordnik:swagger-jaxrs_2.9.1:1.0.1"){
            excludes 'stax-api'
        }
        runtime "com.wordnik:swagger-core_2.9.1:1.0.1"



Thanks

Scott Ryan

Scott Ryan

unread,
Nov 7, 2012, 7:00:41 PM11/7/12
to swagger-sw...@googlegroups.com
I also tried using the technique where you use the listing file in a separate class and I get a ClassNotFound error getting the listing class

java.lang.ClassNotFoundException: class com.company.amp.resource.v100.EventResource not found
    at com.wordnik.swagger.core.SwaggerContext$.loadClass(SwaggerContext.scala:46)
    at com.wordnik.swagger.jaxrs.JavaHelp.getHelp(JavaHelp.scala:56)
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)

tony tam

unread,
Nov 7, 2012, 8:21:01 PM11/7/12
to swagger-sw...@googlegroups.com
Hi Scott, seems like there are some issues with how Grails is loading the classes, see here:


If you can help post a simple grails example (email is fine, too), I'd be happy to sort this out, along with the classloader issue.

Scott Ryan

unread,
Nov 9, 2012, 11:33:17 AM11/9/12
to swagger-sw...@googlegroups.com
I was able to make it work. I had to load the jars into the grails lib directory and that fixed the class loader issue.  Then I had to implement the API Listing class which I also did.  I am able t access both the resource listing and the individual service listing from the direct URL.  If I use the Swagger UI I am able to display the individual resource docs but not the resource listing.  Although the listing and the individual listing are downloaded they never display on the UI  There are no error so not sure how to debug.  Thanks for your help so far.

Scott Ryan

Scott Ryan

unread,
Nov 13, 2012, 12:05:17 PM11/13/12
to swagger-sw...@googlegroups.com
Here is an example that works. I am still having issues with one of my apps but 2 of the other ones work fine.  If you unzip this file and run it with grails run-war on then you can go to

http://localhost:8080/app/api/1.0.0/demo

http://localhost:8080/appname/doc/api.html you can see the swagger ui

The config of the jersey stuff is in the Config.groovy file and the servlet is configured to remove the .format from the URL's
Scott Ryan

tony tam

unread,
Nov 15, 2012, 3:15:59 AM11/15/12
to swagger-sw...@googlegroups.com
Hi Scott, just sent you an email--I think the groovy support is just about there, one issue that I expect to close tomorrow.

Tony

Scott Ryan

unread,
Nov 15, 2012, 10:57:40 AM11/15/12
to swagger-sw...@googlegroups.com
I think if you add

org.grails.jaxrs.url.mappings = ['/api','/api-docs']

it will route the /api-docs stuff correctly

Scott Ryan
President/CTO
Soaring Eagle L.L.C.
Highlands Ranch, Co. 80130
(303) 263-3044
sc...@theryansplace.com
www.soaringeagleco.com

tony tam

unread,
Nov 30, 2012, 12:33:11 AM11/30/12
to swagger-sw...@googlegroups.com, sc...@theryansplace.com

Scott Ryan

unread,
Dec 10, 2012, 5:35:14 PM12/10/12
to swagger-sw...@googlegroups.com, sc...@theryansplace.com
I am finally getting around to implementing this update and had one question. I still have GET s that return lists based on query parameters.  I assume that I still have to implement a separate listing file for each of my services to allow for such a structure?

The other fixes work perfectly.

Scott Ryan

tony tam

unread,
Dec 11, 2012, 8:42:06 AM12/11/12
to swagger-sw...@googlegroups.com, sc...@theryansplace.com
Hi Scott, can you explain more?
Reply all
Reply to author
Forward
0 new messages