Incorrect path levelsfor json api-docs, that swagger-ui can't handle

274 views
Skip to first unread message

Johan Martinsson

unread,
Oct 8, 2014, 6:37:45 AM10/8/14
to swagger-sw...@googlegroups.com
Hi,

I can't get the json paths correct when I deploy to an application server (Jonas). It works when I start a grizzly server, but when I expose the api-docs base path through a servlet. I get a different result, seemingly incompatible with swagger ui.

Here's the correct result, Provided by this class
http://localhost:8085/api-docs/
{ "apiVersion" : "1.0.0",
  "apis" : [ { "path" : "/alive" } ],
  "swaggerVersion" : "1.2"
}


Here's the problematic result that swagger-ui does not seem to handle, provided by Jonas, using this web.xml
http://localhost:9000/swagger-debug/api-docs/
{ "apiVersion" : "1.0.0",
  "apis" : [ { "description" : "description",
        "operations" : [ { "method" : "",
              "nickname" : "",
              "notes" : "",
              "parameters" : [  ],
              "summary" : "Server is alive",
              "type" : "void"
            } ],
        "path" : "/alive"
      } ],
  "basePath" : "http://localhost:9000/lugano-service/rest",
  "resourcePath" : "/",
  "swaggerVersion" : "1.2"
}


I pushed a the stripped down project to github https://github.com/martinsson/swagger-debug

I'm guessing I messed up the configuration of DefaultServletReaderConfig in my web.xml but I'm not sure and I can't get it to work. I need some help, please :)

Yours sincerely
Johan Martinsson

Ron

unread,
Oct 8, 2014, 7:04:49 AM10/8/14
to swagger-sw...@googlegroups.com
Hi Johan,

I'm a bit confused by your sample. It looks like it doesn't use servlets nor JAX-RS to serve your api...

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Johan Martinsson

unread,
Oct 8, 2014, 7:32:16 AM10/8/14
to swagger-sw...@googlegroups.com

Well I'm using Jersey that is served through a servlet and I'm trying to serve the api-docs through another,  both declared in my web.xml. Or am I missing something?

In the working case I'm using Jersey through Grizzly

You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/5Mt_MwMYbag/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.

Ron

unread,
Oct 8, 2014, 7:34:44 AM10/8/14
to swagger-sw...@googlegroups.com
Okay, I'm just blind.

I'll look into the sample again in a few minutes.

Johan Martinsson

unread,
Oct 8, 2014, 7:35:30 AM10/8/14
to swagger-sw...@googlegroups.com

Thank you very much for your help Ron.

Ron

unread,
Oct 8, 2014, 8:33:08 AM10/8/14
to swagger-sw...@googlegroups.com
Just need one more push, since this is a Grizzly project and it also uses a war packaging. How do I run it?
I have very little experience with Grizzly directly.

Johan Martinsson

unread,
Oct 8, 2014, 9:05:27 AM10/8/14
to swagger-swaggersocket
We only use grizzly as a second environment in which to launch the application. It is more convenient for development than waiting the compilation of a war and for an application server to start and redeploy. Swagger works fine in Grizzly. But I need to make it work in a production like environment, that is the JoNaS application server for us. I can upload the jonas binary I'm using tomorrow morning, but I'd guess that the result will be the same in a regular tomcat.

The invalid result that I gave in the first post is the result I get when I run the war built by "mvn package" in JoNaS.

If you don't see any inconsistencies in the web.xml. Then I'll try to run it in tomcat. Else I suppose I'll have to read the code and learn some scala.
Johan Martinsson


Ron

unread,
Oct 8, 2014, 9:07:30 AM10/8/14
to swagger-sw...@googlegroups.com
No worries, I can get JoNaS. Do you use any specific version?

Johan Martinsson

unread,
Oct 8, 2014, 9:14:47 AM10/8/14
to swagger-swaggersocket

I'm using 5.2.4, you need to allow a sun.* package in conf/osgi/defaults.properties. It will tell you which one upon startup (I don't have my machine with me right now)

Johan Martinsson

unread,
Oct 8, 2014, 7:25:26 PM10/8/14
to swagger-swaggersocket
I'm getting the same thing in tomcat. I've got an idea of what the problem might be. I doubt that using 

com.wordnik.swagger.servlet.config.DefaultServletReaderConfig

is appropriate. I'm trying to use 

com.wordnik.swagger.jersey.config.JerseyJaxrsConfig

Instead, but I'm having some other problems with that, but I'm getting too tired to work on it. Going to get some sleep


WARNING: HK2 service reification failed for [com.sun.jersey.core.impl.provider.entity.MimeMultipartProvider] with an exception:

MultiException stack 1 of 2

java.lang.NoClassDefFoundError: javax/mail/internet/ParseException

        at java.lang.Class.getDeclaredConstructors0(Native Method)

        at java.lang.Class.privateGetDeclaredConstructors(Class.java:2658)

        at java.lang.Class.getDeclaredConstructors(Class.java:2007)


Johan Martinsson

unread,
Oct 9, 2014, 4:52:21 AM10/9/14
to swagger-swaggersocket
OK I solved it. The working config is the latest commit in the repo

What I needed to do
- change this in pom.xml
-                       <artifactId>swagger-jaxrs_2.10</artifactId>
+                       <artifactId>swagger-jersey2-jaxrs_2.10</artifactId>
Btw the jersey2 instead of jersey is very important but easy to miss

in the web.xml I needed to serve it through the jersey servlet, by adding the following init params
+               <init-param>
+                       <param-name>jersey.config.server.provider.classnames
+                       </param-name>
+                       <param-value>
+                       com.wordnik.swagger.jersey.listing.ApiListingResourceJSON,
+                       com.wordnik.swagger.jersey.listing.JerseyApiDeclarationProvider,
+                       com.wordnik.swagger.jersey.listing.JerseyResourceListingProvider
+                       </param-value>
+               </init-param>

not by a standalone servlet as I first did as in the initial example. Thank you Ron for your time and your questions that put me on the right track.

Ron

unread,
Oct 9, 2014, 5:10:54 AM10/9/14
to swagger-sw...@googlegroups.com
Thank you for the update, Johan, I'm sure others will find it useful as well.

I'm actually in the process of writing a guide on how to set up your application based on the JAX-RS implementation you use (supporting various configuration options). It'll take some time to become public, but I hope it would solve such issues in the future.

Johan Martinsson

unread,
Oct 9, 2014, 8:33:26 AM10/9/14
to swagger-swaggersocket
and looking at the code of JerseyJaxrsConfig and DefaultServletConfig

It took time to get there simply because I was unable to identify which sample corresponded to my situation. Hence I looked at the wikis, but they are not complete. Code is in scala and not documented.

Also now that I understand how the swagger boot works (the configuration loading), I could probably transpose to any configuration. It is not easy to understand the role of ApiListingResource*, ApiDeclarationProvider, ResourceListingProvider and *Config (like JerseyJaxrsConfig). This is one place where javadoc could probably come in handy. But there is also a need for describing the loading sequence.

I do recognize that these kinds of application server related configuration problems are not easy.

Johan

Ron

unread,
Oct 9, 2014, 8:51:00 AM10/9/14
to swagger-sw...@googlegroups.com
It's worse than you may think since there are subtle differences between JAX-RS implementations. I hope we'll manage to improve it over time.
Reply all
Reply to author
Forward
0 new messages