- Swagger
- Rest Docs
Swagger ์ ์ URL
http://localhost:8080/swagger-ui/index.html
SwaggerConfig
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
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Contact;
import io.swagger.v3.oas.annotations.info.Info;
import org.springframework.context.annotation.Configuration;
@OpenAPIDefinition(
info = @Info(
title = "Side-Project API",
description = "์ฌ์ด๋ํ๋ก์ ํธ API ๋ช
์ธ์",
version = "v1",
contact = @Contact(
name = "beginners",
email = "sample@email.co.kr"
)
)
)
@Configuration
public class SwaggerConfig {
//GroupedOpenApi ์ค์ ์ ํ๋ฉด ๊ทธ๋ฃน ์ค์ ๋ api ๋ค๋ง ๋ฌธ์์ ๋
ธ์ถ
// @Bean
// public GroupedOpenApi sampleGroupOpenApi() {
// String[] paths = {"/member/**"};
//
// return GroupedOpenApi.builder().group("์ํ ๋ฉค๋ฒ API").pathsToMatch(paths)
// .build();
// }
}
SecurityConfig
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
@EnableWebSecurity
@Configuration
public class SecurityConfig {
...
@Bean
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
httpSecurity
// token์ ์ฌ์ฉํ๋ ๋ฐฉ์์ด๊ธฐ ๋๋ฌธ์ csrf๋ฅผ disableํฉ๋๋ค.
.csrf().disable()
.addFilterBefore(corsFilter, UsernamePasswordAuthenticationFilter.class)
.exceptionHandling()
.authenticationEntryPoint(jwtAuthenticationEntryPoint)
.accessDeniedHandler(jwtAccessDeniedHandler)
// enable h2-console
.and()
.headers()
.frameOptions()
.sameOrigin()
// ์ธ์
์ ์ฌ์ฉํ์ง ์๊ธฐ ๋๋ฌธ์ STATELESS๋ก ์ค์
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeHttpRequests()
.requestMatchers(PathRequest.toH2Console()).permitAll()
.requestMatchers( "/swagger-ui/**", "/v3/api-docs/**").permitAll() // Swagger ์ถ๊ฐ
.anyRequest().authenticated()
.and()
.apply(new JwtSecurityConfig(tokenProvider));
return httpSecurity.build();
}
}
MemberController
1
2
3
4
5
6
7
8
9
@Tag(name = "๋ฉค๋ฒ ์ปจํธ๋กค๋ฌ") // Swagger
@RequiredArgsConstructor
@RestController
public class MemberController {
...
}
LoginReqDto
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class LoginReqDto {
@Schema(description = "์ ์ ์ด๋ฉ์ผ", example = "test123@gmail.com") // Swagger
@NotNull
private String email;
@Schema(description = "ํจ์ค์๋", example = "test123!") // Swagger
@NotNull
private String password;
}