Setting scan.all.resources for Swagger in JAXRS

空扰寡人 提交于 2020-01-04 02:22:27

问题


I am using plain vanilla JAXRS in a provided Application Server with Swagger 1.5.18. I can get the Swagger annotated classes to appear in the swagger.json, but I am having trouble setting the Swagger to scan for non annotated classes, those with just the @Path JAXRS annotations.

I currently have the BeanConfig in the Class that is extending Application. I tried using a Servlet that extended DefaultJaxrsConfig with @WebInitParam(name="scan.all.resources", value="true") but that did not work at all.

The documentation states that setting ReaderConfig.scanAllResources would achieve what I am looking for. However, I am not sure of a good way to implement this. Any suggestions?

Current configuration class:

@ApplicationPath("services") 
public class Configuration extends Application {

public Configuration() {
    BeanConfig beanConfig = new BeanConfig();
    beanConfig.setVersion("1.0.0");
    beanConfig.setTitle("SwaggerExample");
    beanConfig.setBasePath("/SwaggerExample/services");
    beanConfig.setResourcePackage("com.xxxxxx.swagger.jaxrs");
    beanConfig.setScan(true);
    beanConfig.setPrettyPrint(true);
} 

Thanks, Brian


回答1:


I did find a way around the issue as posted in the Swagger blog post, by implementing a ReaderListener. However, I would think this could be set at the BeanConfig level. Here is my solution:

@SwaggerDefinition
public class ApiDefinitions implements ReaderListener {

    @Override
    public void afterScan(Reader reader, Swagger swagger) {
    }

    @Override
    public void beforeScan(Reader reader, Swagger swagger) {
        ((DefaultReaderConfig) reader.getConfig()).setScanAllResources(true); 
    }
}

Brian



来源:https://stackoverflow.com/questions/48602795/setting-scan-all-resources-for-swagger-in-jaxrs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!