Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 598
Mizanur Rahman Avatar asked Jun 29 '15 04:06

Mizanur Rahman


People also ask

What does a swagger file contains?

It includes information on how to define paths, parameters, responses, models, security and more. The Swagger Specification itself is open source and available under ASL 2.0.

How do I hide a request field in swagger API?

We can use the hidden property of the annotation to hide a field in the definition of a model object in Swagger UI. Let's try it for the id field: @ApiModelProperty(hidden = true) private int id; In the above scenarios, we find that the id field is hidden for both GET and POST APIs.


2 Answers

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

like image 98
Ralph Avatar answered Sep 22 '22 12:09

Ralph


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

like image 33
Georges Perec Avatar answered Sep 18 '22 12:09

Georges Perec