配置多个Docket,对API接口进行分组,paths函数对API接口进行过滤。
@Bean
public Docket createRestApi(@Value("${swagger.enable:false}") boolean swaggerEnable) {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("全部")
.enable(swaggerEnable)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.xxx.controller"))
.paths(PathSelectors.any())
.build();
}
@Bean
public Docket commonDocket() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("A")
.apiInfo(apiInfo("测试环境通用接口"))
.pathMapping("/")
.select()
.apis(RequestHandlerSelectors.basePackage("com.xxx.controller.aaa"))//指向自己的controller即可
.paths(PathSelectors.any())
.build();
}
@Bean
public Docket commonDocket2() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("B")
.apiInfo(apiInfo("测试环境通用接口"))
.pathMapping("/")
.select()
.apis(RequestHandlerSelectors.basePackage("com.xxx.controller.bbb"))//指向自己的controller即可
.paths((s) -> {
//过滤掉bbb的借口,只展示其他
if (s.indexOf("bbb") != -1) {
return false;
}
return true;
})
.build();
}