Skip to content

Commit

Permalink
Merge pull request #30 from goalSetter09/10th-Kampus-BE-29
Browse files Browse the repository at this point in the history
[DOCS] Swagger 설정
  • Loading branch information
goalSetter09 authored Jan 12, 2025
2 parents b42f6b6 + c0350da commit a6275cd
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 14 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ dependencies {
implementation 'io.jsonwebtoken:jjwt-api:0.12.3'
implementation 'io.jsonwebtoken:jjwt-impl:0.12.3'
implementation 'io.jsonwebtoken:jjwt-jackson:0.12.3'

// Swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.1'
}

tasks.named('test') {
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/com/cotato/kampus/domain/auth/api/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@
import com.cotato.kampus.domain.auth.dto.response.SignupResponse;
import com.cotato.kampus.global.common.dto.DataResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;

@Tag(name = "인증/인가", description = "인증/인가 관련 API")
@RestController
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
@RequestMapping("/v1/api/auth")
Expand All @@ -23,23 +28,18 @@ public class AuthController {
private final AuthService authService;

@PostMapping("/signup")
public ResponseEntity<DataResponse<SignupResponse>> signup(@RequestBody SignupRequest request) {
return ResponseEntity.ok(DataResponse.from(
SignupResponse.of(
authService.signup(
request.email(),
request.uniqueId(),
request.providerId(),
request.username(),
request.nickname(),
request.nationality())
)
)
);
@Operation(summary = "일반 로그인", description = "Client 단에서 소셜 로그인 후 회원가입 요청하는 api")
public ResponseEntity<DataResponse<SignupResponse>> signup(
@Parameter(description = "회원가입 요청 정보", schema = @Schema(implementation = SignupRequest.class))
@RequestBody SignupRequest request) {
return ResponseEntity.ok(DataResponse.from(SignupResponse.of(
authService.signup(request.email(), request.uniqueId(), request.providerId(), request.username(),
request.nickname(), request.nationality()))));
}

@Operation(summary = "서버 헬스 체크", description = "서버 헬스 체크")
@GetMapping("/health")
public ResponseEntity<DataResponse<Void>> health() {
return ResponseEntity.ok(DataResponse.ok());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class SecurityConfig {
"/v1/api/auth/signup",
"/v1/api/products",
"/v1/api/boards/**",
"/swagger-ui/**",
"/v3/api-docs/**",
};

// jwtAuthenticationFilter에서 스킵하는 url
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/com/cotato/kampus/global/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.cotato.kampus.global.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;

@OpenAPIDefinition(
info = @Info(title = "Kampus 프로젝트 API 명세서",
description = "Kampus 서버 API 명세서",
version = "v1")
)
@Configuration
public class SwaggerConfig {

private static final String ACCESS_HEADER_NAME = "Authorization";
private static final String REFRESH_HEADER_NAME = "Refresh-Token";

@Bean
public OpenAPI customOpenAPI() {


// Define the SecurityRequirement to be included in the request
SecurityRequirement securityRequirement = new SecurityRequirement()
.addList(ACCESS_HEADER_NAME)
.addList(REFRESH_HEADER_NAME);

Components components = new Components()
.addSecuritySchemes(ACCESS_HEADER_NAME, new SecurityScheme()
.name(ACCESS_HEADER_NAME)
.type(SecurityScheme.Type.APIKEY)
.in(SecurityScheme.In.HEADER)
.name(ACCESS_HEADER_NAME))
.addSecuritySchemes(REFRESH_HEADER_NAME, new SecurityScheme()
.name(REFRESH_HEADER_NAME)
.type(SecurityScheme.Type.APIKEY)
.in(SecurityScheme.In.HEADER)
.name(REFRESH_HEADER_NAME));

return new OpenAPI()
.addServersItem(new Server().url("https://kampus.kro.kr").description("배포 서버"))
.addServersItem(new Server().url("http://localhost:8080").description("Local Server"))
.addServersItem(new Server().url("http://54.180.123.60:8080").description("Ec2 http 직접 접근(배포 서버 안될 때 사용)"))
.addSecurityItem(securityRequirement)
.components(components);
}
}

0 comments on commit a6275cd

Please sign in to comment.