Swagger Core Jersey 2 – Empty API listing / Resources not listed

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInDigg thisShare on RedditPin on PinterestPrint this pageEmail this to someone

Recently, I tried following “Swagger-Core-Jersey-2.X-Project-Setup-1.5” guide. After doing everything correct, identified that “swagger.json” file does not contain API listing. Output was something similar to :

{“swagger”:”2.0″,”info”:{“version”:”1.0.0″,”title”:””},”host”:”localhost:8080″,”basePath”:”/com.example/rest”,”schemes”:[“http”] }

I was unable to find a solution anywhere around, even though similar issues were discussed here and there. Finally, decided to dig into source code and identified that in line 183 of Reader class, it is expected to add an additional @Api annotation to API classes (in addition to @Path annotation) in order to get it listed in Swagger file. Therefore, an example class would look something like :

package com.example.listing;

import io.swagger.annotations.Api;

import javax.ws.rs.BeanParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Api
@Path("/listing")
@Produces(MediaType.APPLICATION_JSON)
public class ListingService {

	@POST
	@Path("/list")
	public Response list(@BeanParam ListingParam listingParam) {
		Response response = new Response();
                //...
		return response;
	}

}

This is well documented in Swagger-Core Annotations documentation. But surely is easy to miss if you only look at “Swagger-Core-Jersey-2.X-Project-Setup-1.5” documentation and if you are new to Swagger-Core.

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInDigg thisShare on RedditPin on PinterestPrint this pageEmail this to someone

2 comments on “Swagger Core Jersey 2 – Empty API listing / Resources not listed

  1. agar.io cheats June 26, 2016 12:39 PM

    Additionally, it is the PSP agario hack no down load no review in renovation and
    design, but AFAIK( and are described slaughtered), the
    moon became done only and has now sharpened from the superior Mozilla separation – there had no article of Netfront
    side’s prose immediately.

  2. sandip September 8, 2016 2:30 PM

    I have mentioned whatever ur code has,but still facing same issue.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">