Jersey JAX-RS - getting swagger.json but no UI

125 views
Skip to first unread message

Gavin Fitzgerald

unread,
May 22, 2015, 8:01:29 AM5/22/15
to swagger-sw...@googlegroups.com
Hi all,

I'm having an issue hitting the UI endpoint.

Jersey version - 2.12
Swagger version - 1.5.1-M2

I've a programmatically configured jersey web app.
In my ResourceConfig, I set the following for Swagger:

BeanConfig beanConfig = new BeanConfig();
beanConfig
.setVersion("1.0.0");
beanConfig
.setHost("http:localhost:8080");
beanConfig
.setBasePath("/app/v1");
beanConfig
.setResourcePackage("com.app.features");
beanConfig
.setScan(true);



register(beanConfig);


register(new ApiListingResourceJSON());
register(new SwaggerSerializers());


I also have a Bootstrap class:

public class Bootstrap extends HttpServlet {

 
@Override
 
public void init(ServletConfig config) throws ServletException {
   
Info info = new Info()
           
.title("Swagger Sample App")
           
.description("Desc")
           
.termsOfService("http://helloreverb.com/terms/")
           
.contact(new Contact()
                   
.email("api...@swagger.io"))
           
.license(new License()
                   
.name("Apache 2.0")
                   
.url("http://www.apache.org/licenses/LICENSE-2.0.html"));

   
ServletContext context = config.getServletContext();
   
Swagger swagger = new Swagger().info(info);
    context
.setAttribute("swagger", swagger);
 
}
}

My web.xml:

  <welcome-file-list>
   
<welcome-file>index.html</welcome-file>
 
</welcome-file-list>

 
<servlet>
   
<servlet-name>Bootstrap</servlet-name>
   
<servlet-class>com.app.Bootstrap</servlet-class>
   
<load-on-startup>2</load-on-startup>
 
</servlet>

I have copied the contents of the Swagger UI dist to my web app folder.

When I hit the api json endpoints on http://localhost:8080/app/v1/swagger.json I do get the json code, e.g. :
{"swagger":"2.0","info":{"version":"1.0.0"},"host":"http:localhost:8080","basePath":"/app/v1"}

but I don't seem to see the Swagger UI on the paths I would expect (http:localhost:8080/app/v1 or http:localhost:8080/app/v1/app/v1/index.html).

I'm unfortunately not as comfortable with Jersey as I am with Spring, so any assistance would be welcome.

Thanks,
Kind Regards,
Gavin

Ron Ratovsky

unread,
May 26, 2015, 10:48:57 AM5/26/15
to swagger-sw...@googlegroups.com
Hi Gavin,

Have you added the @Api at the top of your resources?
Are your resources directly under the com.app.features package or are they under a sub-package under it?

--
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.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

Gavin Fitzgerald

unread,
May 26, 2015, 11:58:09 AM5/26/15
to swagger-sw...@googlegroups.com
Hi Ron,

Yes, I have, and they are in a sub-package.

On the class I have:

@Path("embedded")
@Api(value="EmbeddedWidgetConfigurationResource", description = "Retrieves and sets configuration for an embedded widget")
public class EmbeddedWidgetConfigurationResource

and on the method I have:
@GET@Path("/configuration")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value="Load a particular widget's configuration for a particular user's advertiser and agency")
public EmbeddedWidgetConfiguration loadWidgetConfiguration(@QueryParam

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ron Ratovsky

unread,
May 26, 2015, 12:03:34 PM5/26/15
to swagger-sw...@googlegroups.com
So two things to try - upgrade to 1.5.2.-M2 first and try again. If that doesn't work, try pointing it directly to the sub-package(s) and not the top one.

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.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

--
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.

Gavin Fitzgerald

unread,
May 27, 2015, 4:34:23 AM5/27/15
to swagger-sw...@googlegroups.com
Hmm, no change after the version change, but the second does update the top level swagger.json to have the full api details :

{"swagger":"2.0","info":{"version":"1.0.0"},"host":"http:localhost:8080","basePath":"/app/v1","tags":[{"name":"EmbeddedWidgetConfigurationResource"}],"paths":{"/embedded/configuration":{"get":{"tags":["EmbeddedWidgetConfigurationResource"],"summary":etc

But still, I cannot seem to load / trigger the Swagger UI (or rather it's endpoint I think).
I just get 204s on app/v1 or on app/v1/index.html.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

--
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-swaggersocket+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ron Ratovsky

unread,
May 27, 2015, 8:46:02 AM5/27/15
to swagger-sw...@googlegroups.com
Have you done anything to integrate the UI with your application?

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.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

--
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.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

--
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.
Reply all
Reply to author
Forward
0 new messages