SwaggerConfig.java
3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package com.glsk.config;
import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
//@ComponentScan("glsk.controller")
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.pathMapping("/")
.select() // 选择那些路径和api会生成document
.apis(RequestHandlerSelectors.any())// 对所有api进行监控
//不显示错误的接口地址
.paths(Predicates.not(PathSelectors.regex("/error*")))//错误路径不监控
.paths(PathSelectors.regex("/.*"))// 对根下所有路径进行监控
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("接口口文档档")
.contact(new Contact("romeo", "", "xxx@qq.com"))
.description("这是SWAGGER_2生成的接口文档")
.termsOfServiceUrl("NO terms of service")
.license("The Apache License, Version 2.0")
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
.version("v1.0")
.build();
}
/* @Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.pathMapping("/")
.select()// 选择那些路径和api会生成document
.apis(RequestHandlerSelectors.any())// 对所有api进行监控
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
//不显示错误的接口地址
.paths(Predicates.not(PathSelectors.regex("/error.*")))// 错误路径不监控
.paths(PathSelectors.regex("/.*"))// 对根下所有路径进行监控
// api过滤器,设置哪些接口会加载创建接口文档
//.apis(RequestHandlerSelectors.basePackage("com.xx.xx"))
// .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
// .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("服务接口文档")
.description("服务接口文档说明:xxx")
.contact(new Contact("55555", "", "jinglf@didihu.com.cn"))
.version("1.0.0")
.build();
}*/
// private ApiInfo apiInfo2() {
// return new ApiInfoBuilder().title("action-swagger")
// .description("swagger实战").termsOfServiceUrl("")
// .version("1.0").build();
// }
//
// @Bean
// public Docket customDocket() {
// return new Docket(DocumentationType.SWAGGER_2)
// .apiInfo(apiInfo())
// .pathMapping("/")
// .select()
// .apis(RequestHandlerSelectors.basePackage("glsk.controller"))//扫描的包路径
// .paths(Predicates.not(PathSelectors.regex("/error.*")))// 错误路径不监控
// .paths(PathSelectors.regex("/.*"))// 对根下所有路径进行监控
// .build();
// }
}