问题
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