@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.regex("/api/.*"))
.build()
.apiInfo(getApiInfo());
}
@Bean
public Docket restfulApi() {
return new Docket(DocumentationType.SWAGGER_2).groupName("RestfulApi")
.genericModelSubstitutes(ResponseEntity.class)
.useDefaultResponseMessages(true)
.forCodeGeneration(false)
.select().paths(getPathRules())
.build().apiInfo(getApiInfo());
}
/**
* 设置过滤规则 这里的过滤规则支持正则匹配
*
* @return
*/
private Predicate<String> getPathRules() {
Iterable<Predicate<String>> ptn_excludes = Arrays.stream(excludePaths.split(","))
.map(p -> ant(p))::iterator;
return not(or(ptn_excludes));
}
private ApiInfo getApiInfo() {
ApiInfo apiInfo = new ApiInfo("系统 - REST API", getDescribe(),
null, null, (Contact) null, null, null);
return apiInfo;
}
private String getDescribe() {
StringBuffer sb = new StringBuffer();
sb.append("<b><font size=\"4\" color=\"red\">接口约定</font>");
return sb.toString();
}
}
网友评论