4
4
package com .sippulse .pet .system .config ;
5
5
6
6
import java .util .Collections ;
7
+ import java .util .List ;
7
8
8
9
import org .springframework .context .annotation .Bean ;
9
10
import org .springframework .context .annotation .Configuration ;
10
11
12
+ import com .google .common .collect .Lists ;
13
+
11
14
import springfox .documentation .builders .PathSelectors ;
12
15
import springfox .documentation .builders .RequestHandlerSelectors ;
13
16
import springfox .documentation .service .ApiInfo ;
17
+ import springfox .documentation .service .ApiKey ;
18
+ import springfox .documentation .service .AuthorizationScope ;
14
19
import springfox .documentation .service .Contact ;
20
+ import springfox .documentation .service .SecurityReference ;
15
21
import springfox .documentation .spi .DocumentationType ;
22
+ import springfox .documentation .spi .service .contexts .SecurityContext ;
16
23
import springfox .documentation .spring .web .plugins .Docket ;
17
24
import springfox .documentation .swagger2 .annotations .EnableSwagger2 ;
18
25
24
31
@ Configuration
25
32
@ EnableSwagger2
26
33
public class SwaggerConfig {
34
+
35
+ public static final String AUTHORIZATION_HEADER = "Authorization" ;
36
+ public static final String DEFAULT_INCLUDE_PATTERN = "/api/.*" ;
27
37
28
38
@ Bean
29
39
public Docket api () {
@@ -32,7 +42,9 @@ public Docket api() {
32
42
.apis (RequestHandlerSelectors .basePackage ("com.sippulse.pet" ))
33
43
.paths (PathSelectors .any ())
34
44
.build ()
35
- .apiInfo (apiInfo ());
45
+ .apiInfo (apiInfo ())
46
+ .securityContexts (Lists .newArrayList (securityContext ()))
47
+ .securitySchemes (Lists .newArrayList (apiKey ()));
36
48
}
37
49
38
50
private ApiInfo apiInfo () {
@@ -41,8 +53,28 @@ private ApiInfo apiInfo() {
41
53
"Pet-Schedule - Interview SIPPULSE" ,
42
54
"v1" ,
43
55
"Terms Of Service Url" ,
44
- new Contact (
"Fabio Figueiredo da Silva" ,
"pet-schedule.xyz " ,
"[email protected] " ),
56
+ new Contact (
"Fabio Figueiredo da Silva" ,
"https:// pet-schedule-br.herokuapp.com/swagger " ,
"[email protected] " ),
45
57
"License of API" , "License of URL" , Collections .emptyList ());
46
58
}
59
+
60
+ private ApiKey apiKey () {
61
+ return new ApiKey ("JWT - Antes de inserir o token colocar a palavra \" Baerer\" seguida de um espaço e pronto." , AUTHORIZATION_HEADER , "header" );
62
+ }
63
+
64
+ private SecurityContext securityContext () {
65
+ return SecurityContext .builder ()
66
+ .securityReferences (defaultAuth ())
67
+ .forPaths (PathSelectors .regex (DEFAULT_INCLUDE_PATTERN ))
68
+ .build ();
69
+ }
70
+
71
+ List <SecurityReference > defaultAuth () {
72
+ AuthorizationScope authorizationScope
73
+ = new AuthorizationScope ("global" , "accessEverything" );
74
+ AuthorizationScope [] authorizationScopes = new AuthorizationScope [1 ];
75
+ authorizationScopes [0 ] = authorizationScope ;
76
+ return Lists .newArrayList (
77
+ new SecurityReference ("JWT" , authorizationScopes ));
78
+ }
47
79
48
80
}
0 commit comments