需求只保留有@ApiOperation的注解方法,声明一个类实现 Predicate,里面也可以添加自定义的逻辑。
@Bean
public Docket createAPI() {
return new Docket(DocumentationType.SWAGGER_2).forCodeGeneration(true).select().apis(RequestHandlerSelectors.any())
//过滤生成链接
.apis(RequestHandlerSelectors.basePackage("com.peppa.crm.web.manage.controller"))
.apis(new Swaggerfilter())
.paths(PathSelectors.any()).build().apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
Contact contact=new Contact("test-crm-swagger","http://sso.qa.test.cn",test@test");
ApiInfo apiInfo = new ApiInfoBuilder().license("Apache License Version 2.0-crm").title("Swagger 集成测试").description("Swagger API Teste").contact(contact).version("1.0").build();
return apiInfo;
}
/**
* 过滤页面路由
*/
class Swaggerfilter implements Predicate<RequestHandler> {
@Override
public boolean apply(@Nullable RequestHandler requestHandler) {
if(requestHandler.findAnnotation(ApiOperation.class).isPresent()){
return true;
}
/* if(requestHandler.findAnnotation(ResponseBody.class).isPresent()|| requestHandler.findControllerAnnotation(ResponseBody.class).isPresent()){
return true;
}*/
return false;
}
}