Mizanur Rahman
Mizanur Rahman

Reputation: 121

Swagger api listing is empty

Recently I have configure swagger with one of my project. Its using jersey2 and JAX-WS on tomcat for restful API. I have used following manual to configure

https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-Jersey-2.X-Project-Setup-1.5

${basepath}/swagger.json response with following

{"swagger":"2.0","info":{"version":"1.0.0","title":""},"host":"localhost:8080","basePath":"/myapi","schemes":["http"]}

Unfortounately it does not contain any api which is under my resource package. I have tried with the answer of following question

swagger - empty listing with no API

But it didn't help either. The above answer using com.wordnik.swagger.* package(s) But with the manual I got io.swagger.* package(s), which doesn't have JaxrsApiReader class

My assumption is swagger couldn't scan my api list from Resource package. But could not figure out which configuration or which code snippet I have missed.

Any help?....

Upvotes: 6

Views: 9646

Answers (2)

Ralph
Ralph

Reputation: 120791

It looks like you forgot to mark the rest endpoints with @Api

Upvotes: 4

Georges Perec
Georges Perec

Reputation: 31

I had the same issue, I used a different approach that worked for me, by adding information only in my Application class. In case you have one, that might help you:

public class MyApi extends Application {

    public MyApi() {
        super();
        BeanConfig beanConfig = new BeanConfig();
        beanConfig.setTitle("MyApi");
        beanConfig.setVersion("0.0.1");
        beanConfig.setSchemes(new String[]{"http", "https"});
        beanConfig.setHost("localhost:8080");
        beanConfig.setBasePath("/mypath");

        //putting only the path to my api unblocked me, I removed "io.swagger.resources"
        beanConfig.setResourcePackage("system.organization.api"); 
        beanConfig.setScan(true);
        beanConfig.setPrettyPrint(true);
    }

    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> s = new HashSet<>();

        s.add(MyApis);

        //for swagger
        s.add(ApiListingResource.class);
        s.add(SwaggerSerializers.class);

        return s;
    }
}

Then, the links of classes with @API annotation appeared in swagger.json

Mostly done with the same manual you used: https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-Jersey-1.X-Project-Setup-1.5

Upvotes: 3

Related Questions