File tree 3 files changed +46
-0
lines changed
src/main/java/codeview/main/config
3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ repositories {
24
24
}
25
25
26
26
dependencies {
27
+ implementation ' org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'
27
28
implementation ' javax.annotation:javax.annotation-api:1.3.2'
28
29
implementation ' javax.servlet:javax.servlet-api:4.0.1'
29
30
implementation ' org.springframework.boot:spring-boot-starter-data-jpa'
Original file line number Diff line number Diff line change @@ -49,6 +49,12 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
49
49
.headers (c -> c .frameOptions (HeadersConfigurer .FrameOptionsConfig ::disable ).disable ())
50
50
.sessionManagement (c -> c .sessionCreationPolicy (SessionCreationPolicy .STATELESS ))
51
51
.authorizeHttpRequests (request -> request .requestMatchers (
52
+ new AntPathRequestMatcher ("/swagger" ),
53
+ new AntPathRequestMatcher ("/swagger-ui.html" ),
54
+ new AntPathRequestMatcher ("/swagger-ui/**" ),
55
+ new AntPathRequestMatcher ("/api-docs" ),
56
+ new AntPathRequestMatcher ("/api-docs/**" ),
57
+ new AntPathRequestMatcher ("/v3/api-docs/**" ),
52
58
new AntPathRequestMatcher ("/" ),
53
59
new AntPathRequestMatcher ("/home" ),
54
60
new AntPathRequestMatcher ("/login" ),
Original file line number Diff line number Diff line change
1
+ package codeview .main .config ;
2
+
3
+
4
+ import io .swagger .v3 .oas .models .Components ;
5
+ import io .swagger .v3 .oas .models .OpenAPI ;
6
+ import io .swagger .v3 .oas .models .info .Info ;
7
+ import io .swagger .v3 .oas .models .security .SecurityRequirement ;
8
+ import io .swagger .v3 .oas .models .security .SecurityScheme ;
9
+ import org .springframework .context .annotation .Bean ;
10
+ import org .springframework .context .annotation .Configuration ;
11
+
12
+ @ Configuration
13
+ public class SwaggerConfig {
14
+ private static final String BEARER_TOKEN_PREFIX = "Bearer" ;
15
+
16
+ @ Bean
17
+ public OpenAPI openAPI (){
18
+ String securityJwtName = "JWT" ;
19
+ SecurityRequirement securityRequirement = new SecurityRequirement ().addList (securityJwtName );
20
+
21
+
22
+ Components components = new Components ()
23
+ .addSecuritySchemes (securityJwtName , new SecurityScheme ()
24
+ .name (securityJwtName )
25
+ .type (SecurityScheme .Type .HTTP )
26
+ .scheme (BEARER_TOKEN_PREFIX )
27
+ .bearerFormat (securityJwtName ));
28
+
29
+ Info info = new Info ()
30
+ .version ("v1.0.0" )
31
+ .title ("codeView API" );
32
+
33
+
34
+ return new OpenAPI ()
35
+ .components (components )
36
+ .info (info );
37
+ }
38
+
39
+ }
You can’t perform that action at this time.
0 commit comments