16
16
17
17
package com .netflix .spinnaker .config ;
18
18
19
- import com .mangofactory .swagger .configuration .SpringSwaggerConfig ;
20
- import com .mangofactory .swagger .models .dto .ApiInfo ;
21
- import com .mangofactory .swagger .plugin .EnableSwagger ;
22
- import com .mangofactory .swagger .plugin .SwaggerSpringMvcPlugin ;
23
- import org .springframework .beans .factory .annotation .Autowired ;
24
19
import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
25
20
import org .springframework .boot .context .properties .ConfigurationProperties ;
26
21
import org .springframework .context .annotation .Bean ;
27
22
import org .springframework .context .annotation .Configuration ;
23
+ import springfox .documentation .builders .PathSelectors ;
24
+ import springfox .documentation .builders .RequestHandlerSelectors ;
25
+ import springfox .documentation .service .ApiInfo ;
26
+ import springfox .documentation .spi .DocumentationType ;
27
+ import springfox .documentation .spring .web .plugins .Docket ;
28
+ import springfox .documentation .swagger2 .annotations .EnableSwagger2 ;
29
+ import com .google .common .base .Predicate ;
28
30
29
31
import java .util .List ;
32
+ import java .util .stream .Collectors ;
30
33
31
- @ EnableSwagger
34
+ import static com .google .common .base .Predicates .or ;
35
+
36
+ @ EnableSwagger2
32
37
@ Configuration
33
38
@ ConditionalOnProperty ("swagger.enabled" )
34
39
@ ConfigurationProperties (prefix = "swagger" )
@@ -38,24 +43,28 @@ public class SwaggerConfig {
38
43
private String contact ;
39
44
private List <String > patterns ;
40
45
41
- @ Autowired
42
- SpringSwaggerConfig springSwaggerConfig ;
43
-
44
46
@ Bean
45
- public SwaggerSpringMvcPlugin swaggerPlugin () {
46
- SwaggerSpringMvcPlugin plugin = new SwaggerSpringMvcPlugin (this .springSwaggerConfig ).apiInfo (apiInfo ());
47
- if (patterns != null && !patterns .isEmpty ()) {
48
- plugin = plugin .includePatterns (patterns .toArray (new String [patterns .size ()]));
49
- }
47
+ public Docket gateApi () {
48
+ return new Docket (DocumentationType .SWAGGER_2 )
49
+ .select ()
50
+ .apis (RequestHandlerSelectors .any ())
51
+ .paths (paths ())
52
+ .build ()
53
+ .apiInfo (apiInfo ());
54
+ }
50
55
51
- return plugin ;
56
+ private Predicate <String > paths () {
57
+ return or (
58
+ patterns .stream ().map (PathSelectors ::regex ).collect (Collectors .toList ())
59
+ );
52
60
}
53
61
54
62
private ApiInfo apiInfo () {
55
63
return new ApiInfo (
56
64
title ,
57
65
description ,
58
66
null ,
67
+ null ,
59
68
contact ,
60
69
null ,
61
70
null
0 commit comments