I am trying to add swagger to my application.
I am following this guide https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-Jersey-2.X-Project-Setup-1.5#using-a-custom-application-subclass
but I have Jersey configured as ResourceConfig like this:
@ApplicationPath("/resources/api")
public class ApiApplication extends ResourceConfig {
public ApiApplication() {
super(MultiPartFeature.class);
packages("my.rest.resources");
register(io.swagger.jaxrs.listing.ApiListingResource.class);
register(io.swagger.jaxrs.listing.SwaggerSerializers.class);
BeanConfig beanConfig = new BeanConfig();
beanConfig.setVersion("1.0.2");
beanConfig.setSchemes(new String[]{"http"});
beanConfig.setHost("localhost:8080");
beanConfig.setBasePath("/resources/api");
beanConfig.setResourcePackage("my.rest.resources");
beanConfig.setScan(true);
}
}
Is this correct?
There is no swagger.json generated.
According to my understanding swagger files should be on the following link http://localhost/api/api-docs/swagger.json
Updated:
Changed BasePath to resources/api
I also get the following exception in tomcat log:
SEVERE: Servlet /XXXXXX threw load() exception
java.lang.NoSuchMethodError: org.reflections.util.ClasspathHelper.forPackage(Ljava/lang/String;[Ljava/lang/ClassLoader;)Ljava/util/Collection;
at io.swagger.jaxrs.config.BeanConfig.classes(BeanConfig.java:189)
at io.swagger.jaxrs.config.BeanConfig.setScan(BeanConfig.java:168)
at my.rest.resources.apps.ApiApplication.<init>(ApiApplication.java:34)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)