-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Feat] swagger config setup #7
Conversation
WalkthroughThis pull request introduces a complete Gradle configuration for a new Spring Boot project. It adds build scripts, wrapper properties, and platform-specific startup scripts for both POSIX and Windows environments. The changes include a main Spring Boot application class, a REST health check endpoint, Swagger configuration for API documentation, and utility classes for managing environment profiles and constants. Additionally, separate YAML configuration files for development and production environments are provided, along with a basic test class to ensure the application's context loads correctly. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant HealthController
Client->>HealthController: GET /api/health
HealthController-->>Client: "ok"
sequenceDiagram
participant SwaggerConfig
participant SpringEnvironmentUtil
participant OpenAPI
SwaggerConfig->>SpringEnvironmentUtil: getCurrentProfile()
SpringEnvironmentUtil-->>SwaggerConfig: return active profile
SwaggerConfig->>SwaggerConfig: Determine server URL based on profile
SwaggerConfig->>OpenAPI: Build OpenAPI object with server info
OpenAPI-->>SwaggerConfig: Configured OpenAPI instance
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 4
🧹 Nitpick comments (9)
src/main/java/com/evenly/blok/global/common/constants/UrlConstants.java (1)
9-9
: Consider making URLs configurable via properties.Instead of hardcoding URLs, consider making them configurable through application properties to support easier maintenance and environment-specific configurations.
src/main/java/com/evenly/blok/global/health/HealthController.java (1)
12-14
: Standardize API response format.Consider returning a structured response object instead of a plain string for consistency with other APIs. This would also make it easier to add more health-related information in the future.
- public String healthCheck() { - return "ok"; + public HealthResponse healthCheck() { + return new HealthResponse("ok", LocalDateTime.now()); + }Additionally, consider adding logging for monitoring purposes:
public String healthCheck() { + log.info("Health check requested"); return "ok"; }
src/main/java/com/evenly/blok/global/health/HealthApi.java (1)
9-9
: Consider internationalization for API documentation.The API documentation uses Korean text. Consider implementing internationalization support for the documentation to make it accessible to a wider audience.
Also applies to: 12-12
src/main/java/com/evenly/blok/global/common/constants/EnvironmentConstants.java (1)
3-3
: Consider simplifying the constants structure.The current implementation has an inner
Constants
class and uses static imports, which might lead to naming conflicts. Consider moving the constants directly into the enum:-import static com.evenly.blok.global.common.constants.EnvironmentConstants.Constants.*; @Getter @AllArgsConstructor public enum EnvironmentConstants { - PROD(PROD_ENV), - DEV(DEV_ENV), - LOCAL(LOCAL_ENV); + PROD("prod"), + DEV("dev"), + LOCAL("local"); private final String value; - @NoArgsConstructor(access = AccessLevel.PRIVATE) - public static class Constants { - public static final String PROD_ENV = "prod"; - public static final String DEV_ENV = "dev"; - public static final String LOCAL_ENV = "local"; - public static final List<String> PROD_AND_DEV_ENV = List.of(PROD_ENV, DEV_ENV); - } + public static final List<String> PROD_AND_DEV_ENV = List.of(PROD.getValue(), DEV.getValue()); }Also applies to: 21-27
src/main/java/com/evenly/blok/global/util/SpringEnvironmentUtil.java (2)
19-24
: Consider adding null check and validation for environment profiles.The
getCurrentProfile
method assumes that the environment profiles are valid. Consider adding validation to handle edge cases.public String getCurrentProfile() { + if (environment == null || environment.getActiveProfiles().length == 0) { + return LOCAL_ENV; + } return getActiveProfiles() .filter(profile -> profile.equals(PROD_ENV) || profile.equals(DEV_ENV)) .findFirst() .orElse(LOCAL_ENV); }
34-36
: Consider caching the profile check results.The
isProdAndDevProfile
method might be called frequently. Consider caching the result to improve performance.+ private Boolean isProdAndDevProfileCache; + public boolean isProdAndDevProfile() { + if (isProdAndDevProfileCache == null) { + isProdAndDevProfileCache = getActiveProfiles().anyMatch(PROD_AND_DEV_ENV::contains); + } + return isProdAndDevProfileCache; }src/main/resources/application-prod.yml (1)
39-39
: Nitpick: Missing Newline at End of File
Adding a newline at the end of this file will help satisfy YAML linting recommendations.🧰 Tools
🪛 YAMLlint (1.35.1)
[error] 39-39: no new line character at the end of file
(new-line-at-end-of-file)
src/main/resources/appication-dev.yml (2)
1-39
: File Naming Conventions: Verify Filename
It appears the filename is "appication-dev.yml", which might be a typo compared to the expected "application-dev.yml" as mentioned in the PR objectives. Please confirm and, if needed, rename the file to match Spring Boot’s default configuration naming convention.🧰 Tools
🪛 YAMLlint (1.35.1)
[error] 39-39: no new line character at the end of file
(new-line-at-end-of-file)
39-39
: New Line at End-of-File: Correct YAML Formatting
Static analysis flagged that there is no newline at the end of this file. Please add a newline at the end to adhere to YAML formatting standards and avoid potential issues in certain environments.🧰 Tools
🪛 YAMLlint (1.35.1)
[error] 39-39: no new line character at the end of file
(new-line-at-end-of-file)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
gradle/wrapper/gradle-wrapper.jar
is excluded by!**/*.jar
📒 Files selected for processing (15)
build.gradle
(1 hunks)gradle/wrapper/gradle-wrapper.properties
(1 hunks)gradlew
(1 hunks)gradlew.bat
(1 hunks)settings.gradle
(1 hunks)src/main/java/com/evenly/blok/BlokApplication.java
(1 hunks)src/main/java/com/evenly/blok/global/common/constants/EnvironmentConstants.java
(1 hunks)src/main/java/com/evenly/blok/global/common/constants/UrlConstants.java
(1 hunks)src/main/java/com/evenly/blok/global/config/swagger/SwaggerConfig.java
(1 hunks)src/main/java/com/evenly/blok/global/health/HealthApi.java
(1 hunks)src/main/java/com/evenly/blok/global/health/HealthController.java
(1 hunks)src/main/java/com/evenly/blok/global/util/SpringEnvironmentUtil.java
(1 hunks)src/main/resources/appication-dev.yml
(1 hunks)src/main/resources/application-prod.yml
(1 hunks)src/test/java/com/evenly/blok/BlokApplicationTests.java
(1 hunks)
✅ Files skipped from review due to trivial changes (4)
- settings.gradle
- src/main/java/com/evenly/blok/BlokApplication.java
- src/test/java/com/evenly/blok/BlokApplicationTests.java
- gradle/wrapper/gradle-wrapper.properties
🧰 Additional context used
🪛 YAMLlint (1.35.1)
src/main/resources/application-prod.yml
[error] 39-39: no new line character at the end of file
(new-line-at-end-of-file)
src/main/resources/appication-dev.yml
[error] 39-39: no new line character at the end of file
(new-line-at-end-of-file)
🔇 Additional comments (15)
gradlew.bat (1)
1-95
: LGTM! Standard Gradle wrapper script.This is the standard Gradle wrapper batch script for Windows with proper error handling and environment checks.
gradlew (1)
1-253
: LGTM! Standard Gradle wrapper script.This is the standard Gradle wrapper shell script for POSIX systems with proper error handling and environment checks.
build.gradle (7)
1-5
: Plugins and Dependency Management Configuration Validated
The plugins, including the Java plugin, Spring Boot (v3.4.2), and Spring Dependency Management (v1.1.7), are correctly applied. This configuration aligns with the project’s requirements.
7-9
: Project Metadata is Correctly Defined
The group IDcom.evenly
and version0.0.1-SNAPSHOT
are properly set.
10-15
: Java Toolchain Configuration is Set Appropriately
Specifying Java 17 via the toolchain ensures compatibility with Spring Boot 3.4.2.
16-20
: Annotation Processing Configuration is Correct
Extending thecompileOnly
configuration fromannotationProcessor
ensures proper handling of Lombok annotations.
22-25
: Repository Declaration is Appropriate
UsingmavenCentral()
as the repository is standard and sufficient for the declared dependencies.
26-35
: Dependencies are Well Specified
All required dependencies for Spring Boot Web, Data JPA, OpenAPI documentation, Lombok, MySQL connectivity, and testing are properly declared. The OpenAPI dependency (springdoc-openapi-starter-webmvc-ui:2.7.0
) aligns with the PR objectives.
37-39
: JUnit Platform Configuration is Correct
The test task is correctly configured to use the JUnit platform.src/main/resources/application-prod.yml (3)
1-10
: Production Datasource Configuration
The datasource configuration for production is correctly set up with environment variables, ensuring that credentials remain externalized and secure.
11-25
: JPA and Hibernate Settings for Production
Hibernate is configured appropriately for production: SQL display is disabled (show_sql: false
,use_sql_comments: false
), and the default schema is set toproduction
. This is in line with best practices for production environments.
26-39
: Swagger and SpringDoc Configuration for Production
The Swagger configuration in production mirrors the development setup to ensure consistent API documentation while applying production-safe settings.🧰 Tools
🪛 YAMLlint (1.35.1)
[error] 39-39: no new line character at the end of file
(new-line-at-end-of-file)
src/main/resources/appication-dev.yml (3)
1-10
: Spring Configuration and Datasource Setup: Validate Environment Variables
The datasource settings correctly use environment variables (e.g.,${DB_HOST}
,${DB_PORT}
, etc.) to externalize connection parameters. Ensure that these environment variables are properly set in your development environment to avoid connection issues.
11-24
: JPA Configuration Review: Confirm Hibernate and Schema Settings
The JPA configuration usesddl-auto: update
, which is acceptable for development. The explicit naming strategy and thedefault_schema: development
are clear and beneficial. Just verify that these settings are appropriate for your development workflow and that you plan to revise them for production if necessary.
26-39
: Swagger and Springdoc Setup: Clarify API Documentation Settings
The Swagger configuration defines the API version and custom UI settings, while Springdoc settings enforce the media types. The parameterurls-primary-name
set to "16th" is unusual—please confirm that this value is intentional and documented if it refers to a specific API grouping or versioning nuance. Additionally, disabling the default Swagger URL should align with your documentation strategy.🧰 Tools
🪛 YAMLlint (1.35.1)
[error] 39-39: no new line character at the end of file
(new-line-at-end-of-file)
public enum UrlConstants { | ||
LOCAL_SERVER_URL("http://localhost:8080"), | ||
; |
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.
🛠️ Refactor suggestion
Add missing URL constants for dev and prod environments.
Based on the PR objectives, this enum should include URL constants for development and production environments to support Swagger configuration across different environments.
public enum UrlConstants {
LOCAL_SERVER_URL("http://localhost:8080"),
+ DEV_SERVER_URL("https://dev-api.evenly.com"),
+ PROD_SERVER_URL("https://api.evenly.com"),
;
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
public enum UrlConstants { | |
LOCAL_SERVER_URL("http://localhost:8080"), | |
; | |
public enum UrlConstants { | |
LOCAL_SERVER_URL("http://localhost:8080"), | |
DEV_SERVER_URL("https://dev-api.evenly.com"), | |
PROD_SERVER_URL("https://api.evenly.com"), | |
; | |
} |
content = @Content(mediaType = "text/html;charset=UTF-8", | ||
schema = @Schema(type = "string", example = "ok"))) |
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.
🛠️ Refactor suggestion
Fix content type mismatch.
The content type is set to "text/html" but the endpoint returns a plain string. Consider using "text/plain" or "application/json" if you plan to return a structured response.
- content = @Content(mediaType = "text/html;charset=UTF-8",
+ content = @Content(mediaType = "application/json;charset=UTF-8",
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
content = @Content(mediaType = "text/html;charset=UTF-8", | |
schema = @Schema(type = "string", example = "ok"))) | |
content = @Content(mediaType = "application/json;charset=UTF-8", | |
schema = @Schema(type = "string", example = "ok"))) |
// TODO: 서비스명 정해지면 바꾸기 | ||
private static final String SERVER_NAME = "16th 2ven"; | ||
private static final String API_TITLE = "16th 2ven 서버 API 문서"; | ||
private static final String API_DESCRIPTION = "16th 2ven 서버 API 문서입니다."; | ||
private static final String GITHUB_URL = "https://github.com/depromeet/16th-team2-BE"; |
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.
🛠️ Refactor suggestion
Remove or address TODO comment and hardcoded strings.
The TODO comment indicates that the service name needs to be updated. Consider moving these strings to configuration properties.
- // TODO: 서비스명 정해지면 바꾸기
- private static final String SERVER_NAME = "16th 2ven";
- private static final String API_TITLE = "16th 2ven 서버 API 문서";
- private static final String API_DESCRIPTION = "16th 2ven 서버 API 문서입니다.";
+ @Value("${swagger.server-name}")
+ private String serverName;
+ @Value("${swagger.api-title}")
+ private String apiTitle;
+ @Value("${swagger.api-description}")
+ private String apiDescription;
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
// TODO: 서비스명 정해지면 바꾸기 | |
private static final String SERVER_NAME = "16th 2ven"; | |
private static final String API_TITLE = "16th 2ven 서버 API 문서"; | |
private static final String API_DESCRIPTION = "16th 2ven 서버 API 문서입니다."; | |
private static final String GITHUB_URL = "https://github.com/depromeet/16th-team2-BE"; | |
@Value("${swagger.server-name}") | |
private String serverName; | |
@Value("${swagger.api-title}") | |
private String apiTitle; | |
@Value("${swagger.api-description}") | |
private String apiDescription; | |
private static final String GITHUB_URL = "https://github.com/depromeet/16th-team2-BE"; |
private String getServerUrl() { | ||
return switch (springEnvironmentUtil.getCurrentProfile()) { | ||
// TODO: prod, dev 연결 | ||
// case "prod" -> UrlConstants.PROD_SERVER_URL.getValue(); | ||
// case "dev" -> UrlConstants.DEV_SERVER_URL.getValue(); | ||
default -> UrlConstants.LOCAL_SERVER_URL.getValue(); | ||
}; | ||
} |
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.
💡 Codebase verification
Implement Missing Constants
The PROD_SERVER_URL
and DEV_SERVER_URL
constants are missing in the UrlConstants.java
enum. Currently, only LOCAL_SERVER_URL
is defined. Please update UrlConstants.java
by adding the production and development URL entries, and then adjust the getServerUrl()
method in SwaggerConfig.java
to utilize them as intended.
- File:
src/main/java/com/evenly/blok/global/common/constants/UrlConstants.java
- File:
src/main/java/com/evenly/blok/global/config/swagger/SwaggerConfig.java
🔗 Analysis chain
Implement production and development server URLs.
The commented-out code for production and development URLs needs to be implemented.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check if the URL constants are defined
rg -A 2 "PROD_SERVER_URL|DEV_SERVER_URL" src/main/java/com/evenly/blok/global/common/constants/UrlConstants.java
Length of output: 114
Script:
#!/bin/bash
# Display the content of UrlConstants.java to verify if production and development URLs are defined
cat src/main/java/com/evenly/blok/global/common/constants/UrlConstants.java
Length of output: 318
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.
대상 브랜치가 develop으로 잘못 설정되어있어 Files changed가 많이 잡혀 리뷰하기가 힘든 것 같아요 ㅠㅠㅠㅠ 제가 바꿀까하다가 혹시 잘못될까 싶어 요청드립니다! 바꿔주시면 다시 PR 확인하겠습니다 :)
대왕 큰 실수를 해버렸네요..!ㅜㅜ 다시 올리겠습니다!!!! |
관련 이슈가 있다면 적어주세요.
issue #2
📌 개발 이유
💻 수정 사항
1. Swagger 설정 추가 (
SwaggerConfig.java
)swagger.version
값을application.yml
에서 주입받도록 설정.SpringEnvironmentUtil
을 활용.Info
객체에 정의 (제목, 설명, 버전, GitHub 링크 포함).2. URL 및 환경 상수 정의 (
UrlConstants.java
,EnvironmentConstants.java
)UrlConstants.java
8080
), 로컬 웹(3000
) URL 상수 추가.EnvironmentConstants.java
prod
,dev
,local
환경 상수 추가.3. 현재 활성화된 Spring Profile을 반환하는 유틸리티 (
SpringEnvironmentUtil.java
)prod
,dev
,local
중 하나로 반환.isProdProfile()
,isDevProfile()
,isProdAndDevProfile()
등의 메서드 추가.4. Swagger 관련 설정 추가 (
appication-dev.yml
,application-prod.yml
)/swagger-ui
로 설정.application/json;charset=UTF-8
로 지정.5. 헬스 체크 API 문서화 (
HealthApi.java
,HealthController.java
)HealthApi.java
: API 설명을 추가하는 Swagger 어노테이션 적용.HealthController.java
:/api/health
엔드포인트에서"ok"
응답을 반환.🧪 테스트 방법
http://localhost:8080/swagger-ui/index.html
/api/health
엔드포인트 호출 후"ok"
응답이 오는지 확인.⛳️ 고민한 점 || 궁금한 점
prod
,dev
서버 URL이 연결되지 않아, 향후 배포 서버 주소 확정 후 반영🎯 리뷰 포인트
EnvironmentConstants
,UrlConstants
와SpringEnvironmentUtil
유틸리티 를 적용했는데, 그 필요성에 대해 논의되지 않은 상태라 이에 대해 의견 부탁드립니다!Summary by CodeRabbit