-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jpa Auditing, Swagger 설정 #27
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,40 @@ | ||
plugins { | ||
id 'java' | ||
id 'org.springframework.boot' version '3.1.1' | ||
id 'io.spring.dependency-management' version '1.1.0' | ||
id 'java' | ||
id 'org.springframework.boot' version '3.1.1' | ||
id 'io.spring.dependency-management' version '1.1.0' | ||
} | ||
|
||
group = 'com' | ||
version = '0.0.1-SNAPSHOT' | ||
|
||
java { | ||
sourceCompatibility = '17' | ||
sourceCompatibility = '17' | ||
} | ||
|
||
configurations { | ||
compileOnly { | ||
extendsFrom annotationProcessor | ||
} | ||
compileOnly { | ||
extendsFrom annotationProcessor | ||
} | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' | ||
implementation 'org.springframework.boot:spring-boot-starter-validation' | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
compileOnly 'org.projectlombok:lombok' | ||
runtimeOnly 'com.h2database:h2' | ||
annotationProcessor 'org.projectlombok:lombok' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' | ||
implementation 'org.springframework.boot:spring-boot-starter-validation' | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0' | ||
|
||
runtimeOnly 'com.h2database:h2' | ||
|
||
compileOnly 'org.projectlombok:lombok' | ||
annotationProcessor 'org.projectlombok:lombok' | ||
|
||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
} | ||
|
||
tasks.named('test') { | ||
useJUnitPlatform() | ||
useJUnitPlatform() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.votogether.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
|
||
@Configuration | ||
@EnableJpaAuditing | ||
public class JpaConfig { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.votogether.config; | ||
|
||
import io.swagger.v3.oas.models.OpenAPI; | ||
import io.swagger.v3.oas.models.info.Info; | ||
import io.swagger.v3.oas.models.servers.Server; | ||
import java.util.List; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class OpenAPIConfig { | ||
|
||
@Value("${votogether.openapi.dev-url}") | ||
private String devUrl; | ||
|
||
@Value("${votogether.openapi.prod-url}") | ||
private String prodUrl; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 필드를 final로 지정하지 않은 이유가 있으신가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
해당 값도 final로 설정하면 좋을 것 같아 검색을 통해 찾아보았더니 생성자에서 |
||
|
||
@Bean | ||
public OpenAPI openAPI() { | ||
final Server devServer = new Server(); | ||
devServer.setUrl(devUrl); | ||
devServer.description("개발 환경 서버 URL"); | ||
|
||
final Server prodServer = new Server(); | ||
prodServer.setUrl(prodUrl); | ||
prodServer.description("운영 환경 서버 URL"); | ||
|
||
final Info info = new Info() | ||
.title("VoTogether API") | ||
.version("v1.0.0") | ||
.description("보투게더 API"); | ||
|
||
return new OpenAPI() | ||
.info(info) | ||
.servers(List.of(devServer, prodServer)); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.votogether.domain.healthcheck.controller; | ||
|
||
import com.votogether.domain.healthcheck.service.HealthCheckService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Tag(name = "헬스 체크", description = "헬스 체크 API") | ||
@RequiredArgsConstructor | ||
@RequestMapping("/health-check") | ||
@RestController | ||
public class HealthCheckController { | ||
|
||
private final HealthCheckService healthCheckService; | ||
|
||
@Operation(summary = "헬스 체크 조회", description = "서버의 작동 여부 확인을 위해 헬스 체크를 조회한다.") | ||
@ApiResponse(responseCode = "200", description = "헬스 체크 조회 성공") | ||
@GetMapping | ||
public ResponseEntity<String> check() { | ||
final String response = healthCheckService.check(); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.votogether.domain.healthcheck.service; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class HealthCheckService { | ||
|
||
public String check() { | ||
return "health-check"; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,8 @@ logging: | |
descriptor: | ||
sql: | ||
BasicBinder: TRACE | ||
|
||
votogether: | ||
openapi: | ||
dev-url: http://localhost:8080 | ||
prod-url: http://votogether.com | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,8 @@ | |
@SpringBootTest | ||
class VotogetherApplicationTests { | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
@Test | ||
void contextLoads() { | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 클래스 명을 OpenAPIConfig라고 하신 이유가 궁금합니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swagger라는 명칭을 사용하지 않은 이유가 궁금한 것으로 해석했는데 맞을까요?!
저문의 질문 덕분에 저도 Swagger와 OpenAPI의 차이에 대해 알아볼 수 있었습니다 :)
OpenAPI
: 축약되어 있는 표현으로 조금 더 자세히 기술하면 OpenAPI Spec이라고 합니다. Restful API 디자인에 대한 정의 표준으로 서비스에서 제공하는 API의 기능과 엔드 포인트를 개발자나 시스템이 자동으로 발견하고 처리하는데 필요한 정보를 제공합니다.Swagger
: OpenAPI Spec에 맞게 디자인하고 문서화하고 빌드하기 위한 도구들의 모음을 의미합니다.해당 설정에서는 OpenAPI Spec에 대해 설정하는 부분이기에 OpenAPIConfig라고 정하게 되었습니다!