Skip to content

Commit 0bc05bc

Browse files
committed
docs: google oauth swagger apply
1 parent 5715c21 commit 0bc05bc

File tree

6 files changed

+94
-1
lines changed

6 files changed

+94
-1
lines changed

noweekend-core/core-api/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ dependencies {
1414
implementation("org.springframework.boot:spring-boot-starter-security")
1515

1616
testImplementation(project(":noweekend-tests:api-docs"))
17+
18+
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0") {
19+
exclude(group = "io.swagger.core.v3", module = "swagger-annotations")
20+
}
21+
implementation("io.swagger.core.v3:swagger-annotations:2.2.15")
1722
}
1823

1924
tasks.named<BootJar>("bootJar") {

noweekend-core/core-api/src/main/kotlin/noweekend/core/api/config/SecurityConfig.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class SecurityConfig {
2828
"/health",
2929
"/api-docs/**",
3030
"/swagger-ui/**",
31+
"/favicon.ico",
3132
),
3233
"deny" to arrayOf(),
3334
)
@@ -41,6 +42,7 @@ class SecurityConfig {
4142
"deny" to arrayOf(
4243
"/api-docs/**",
4344
"/swagger-ui/**",
45+
"/favicon.ico",
4446
),
4547
)
4648

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package noweekend.core.api.config
2+
3+
import io.swagger.v3.oas.models.Components
4+
import io.swagger.v3.oas.models.OpenAPI
5+
import io.swagger.v3.oas.models.info.Info
6+
import io.swagger.v3.oas.models.security.SecurityRequirement
7+
import io.swagger.v3.oas.models.security.SecurityScheme
8+
import io.swagger.v3.oas.models.servers.Server
9+
import org.springframework.context.annotation.Bean
10+
import org.springframework.context.annotation.Configuration
11+
12+
@Configuration
13+
class SwaggerConfig {
14+
@Bean
15+
fun noWeekendApi(): OpenAPI {
16+
val info =
17+
Info()
18+
.title("noweekend Server API")
19+
.description("noweekend Server API 명세서")
20+
.version("v1.0.0")
21+
22+
val jwtSchemeName = "JWT TOKEN"
23+
24+
val securityRequirement = SecurityRequirement().addList(jwtSchemeName)
25+
26+
val components =
27+
Components()
28+
.addSecuritySchemes(
29+
jwtSchemeName,
30+
SecurityScheme()
31+
.name(jwtSchemeName)
32+
.type(SecurityScheme.Type.HTTP)
33+
.scheme("bearer")
34+
.bearerFormat("JWT"),
35+
)
36+
37+
return OpenAPI()
38+
.addServersItem(Server().url("https://noweekend.store"))
39+
.info(info)
40+
.addSecurityItem(securityRequirement)
41+
.components(components)
42+
}
43+
}

noweekend-core/core-api/src/main/kotlin/noweekend/core/api/controller/v1/AuthController.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package noweekend.core.api.controller.v1
22

3+
import io.swagger.v3.oas.annotations.Operation
4+
import io.swagger.v3.oas.annotations.media.Content
5+
import io.swagger.v3.oas.annotations.media.Schema
6+
import io.swagger.v3.oas.annotations.tags.Tag
37
import noweekend.client.google.GoogleClient
48
import noweekend.client.google.GoogleUserInfoRequest
59
import noweekend.core.api.controller.v1.request.LoginRequest
@@ -11,13 +15,40 @@ import org.springframework.web.bind.annotation.PostMapping
1115
import org.springframework.web.bind.annotation.RequestBody
1216
import org.springframework.web.bind.annotation.RequestMapping
1317
import org.springframework.web.bind.annotation.RestController
18+
import io.swagger.v3.oas.annotations.parameters.RequestBody as SwaggerRequestBody
19+
import io.swagger.v3.oas.annotations.responses.ApiResponse as SwaggerApiResponse
1420

21+
@Tag(name = "인증", description = "소셜 로그인 및 인증 API")
1522
@RestController
1623
@RequestMapping("/api/v1/login")
1724
class AuthController(
1825
private val authService: AuthService,
1926
private val googleClient: GoogleClient,
2027
) {
28+
29+
@Operation(
30+
summary = "구글 로그인",
31+
description = "구글 AccessToken을 이용한 회원 인증/가입 처리",
32+
requestBody = SwaggerRequestBody(
33+
required = true,
34+
content = [
35+
Content(
36+
schema = Schema(implementation = LoginRequest::class),
37+
),
38+
],
39+
),
40+
responses = [
41+
SwaggerApiResponse(
42+
responseCode = "200",
43+
description = "로그인 성공",
44+
content = [Content(schema = Schema(implementation = GoogleLoginResponse::class))],
45+
),
46+
SwaggerApiResponse(
47+
responseCode = "400",
48+
description = "잘못된 요청",
49+
),
50+
],
51+
)
2152
@PostMapping("/google")
2253
fun loginWithGoogle(
2354
@Validated @RequestBody req: LoginRequest,
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
package noweekend.core.api.controller.v1.request
22

3+
import io.swagger.v3.oas.annotations.media.Schema
34
import jakarta.validation.constraints.NotBlank
45

6+
@Schema(description = "구글 로그인 요청 DTO")
57
data class LoginRequest(
6-
@field:NotBlank(message = "accessToken은 필수입니다.") val accessToken: String,
8+
@field:NotBlank(message = "accessToken은 필수입니다.")
9+
@Schema(description = "구글 OAuth AccessToken", example = "ya29.a0Af...")
10+
val accessToken: String,
11+
12+
@Schema(description = "사용자 이름 (선택)", example = "홍길동")
713
val name: String?,
814
)
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
package noweekend.core.api.controller.v1.response
22

3+
import io.swagger.v3.oas.annotations.media.Schema
4+
5+
@Schema(description = "구글 로그인 응답 DTO")
36
data class GoogleLoginResponse(
7+
@Schema(description = "구글 이메일", example = "[email protected]")
48
val email: String,
9+
@Schema(description = "이미 가입된 회원 여부")
510
val exists: Boolean,
11+
@Schema(description = "발급된 액세스 토큰", example = "eyJhbGciOiJIUzI1NiIsInR5cCI6...")
612
val accessToken: String,
713
)

0 commit comments

Comments
 (0)