|
@ -9,10 +9,15 @@ import springfox.documentation.builders.ApiInfoBuilder;
|
9
|
9
|
import springfox.documentation.builders.PathSelectors;
|
10
|
10
|
import springfox.documentation.builders.RequestHandlerSelectors;
|
11
|
11
|
import springfox.documentation.service.ApiInfo;
|
|
12
|
import springfox.documentation.service.ApiKey;
|
12
|
13
|
import springfox.documentation.spi.DocumentationType;
|
13
|
14
|
import springfox.documentation.spring.web.plugins.Docket;
|
14
|
15
|
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
15
|
16
|
|
|
17
|
import java.util.List;
|
|
18
|
|
|
19
|
import static com.google.common.collect.Lists.newArrayList;
|
|
20
|
|
16
|
21
|
@Configuration
|
17
|
22
|
@EnableSwagger2
|
18
|
23
|
public class SwaggerConfig implements WebMvcConfigurer {
|
|
@ -24,15 +29,19 @@ public class SwaggerConfig implements WebMvcConfigurer {
|
24
|
29
|
registry.addResourceHandler("/swagger/**").addResourceLocations("classpath:/static/swagger/");
|
25
|
30
|
}
|
26
|
31
|
|
|
32
|
|
27
|
33
|
@Bean
|
28
|
34
|
public Docket createRestApi() {
|
29
|
35
|
return new Docket(DocumentationType.SWAGGER_2)
|
30
|
36
|
.apiInfo(apiInfo())
|
31
|
37
|
.select()
|
32
|
|
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) //加了ApiOperation注解的方法,生成接口文档
|
33
|
|
//.apis(RequestHandlerSelectors.basePackage("io.renren.modules.job.controller")) //包下的类,生成接口文档
|
|
38
|
//加了ApiOperation注解的类,才生成接口文档
|
|
39
|
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
|
|
40
|
//包下的类,才生成接口文档
|
|
41
|
//.apis(RequestHandlerSelectors.basePackage("io.renren.controller"))
|
34
|
42
|
.paths(PathSelectors.any())
|
35
|
|
.build();
|
|
43
|
.build()
|
|
44
|
.securitySchemes(security());
|
36
|
45
|
}
|
37
|
46
|
|
38
|
47
|
private ApiInfo apiInfo() {
|
|
@ -40,8 +49,14 @@ public class SwaggerConfig implements WebMvcConfigurer {
|
40
|
49
|
.title("人人开源")
|
41
|
50
|
.description("renren-fast文档")
|
42
|
51
|
.termsOfServiceUrl("http://www.renren.io")
|
43
|
|
.version("2.0")
|
|
52
|
.version("2.1")
|
44
|
53
|
.build();
|
45
|
54
|
}
|
46
|
55
|
|
|
56
|
private List<ApiKey> security() {
|
|
57
|
return newArrayList(
|
|
58
|
new ApiKey("token", "token", "header")
|
|
59
|
);
|
|
60
|
}
|
|
61
|
|
47
|
62
|
}
|