[Chore] SpringDoc Swagger UI 설정 추가 - #24
Conversation
WalkthroughSpringDoc OpenAPI UI 의존성을 프로젝트에 추가하고, API 메타데이터(제목, 버전, 설명)를 설정하는 OpenAPI 빈을 등록하는 Swagger 설정을 구현했습니다. 파일 형식도 정규화했습니다. Changes
🔍 리뷰 의견SwaggerConfig.kt에 대한 제안: 현재 Info 객체에 설정된 메타데이터가 하드코딩되어 있습니다. 애플리케이션의 버전이 변경될 때마다 코드를 수정해야 하는 상황을 피하기 위해, 다음과 같이 `@Configuration`
class SwaggerConfig(
`@Value`("\${spring.application.name}")
private val applicationName: String,
`@Value`("\${app.api.version:1.0.0}")
private val apiVersion: String,
`@Value`("\${app.api.description:API Documentation}")
private val apiDescription: String
) {
`@Bean`
fun openAPI(): OpenAPI {
return OpenAPI()
.info(
Info()
.title(applicationName)
.version(apiVersion)
.description(apiDescription)
)
}
}이렇게 하면 Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📊 테스트 커버리지 리포트
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/kotlin/com/team2/server/common/config/SwaggerConfig.kt (1)
8-18: OpenAPI 빈 정의는 깔끔합니다. 다만 운영 환경에서의 노출 정책을 함께 고려해 주세요.PR 설명에서도 논의 포인트로 적어주신 부분인데, 현재 프로젝트에는
spring-boot-starter-security가 없어/swagger-ui/**와/v3/api-docs/**가 모든 요청에 그대로 열려 있는 상태입니다. 운영 배포 시 의도치 않게 API 스펙·내부 엔드포인트가 외부에 노출될 수 있어, 최소한 운영 프로필에서는 비활성화하는 가드를 두시는 걸 권합니다.가장 가벼운 방법은
application-prod.yml(혹은 운영 프로필)에서 springdoc 자체를 끄는 것입니다.# application-prod.yml springdoc: api-docs: enabled: false swagger-ui: enabled: false또는 빈 자체를 dev/local 프로필로 한정하고 싶다면 클래스에 프로필을 붙이는 방법도 있습니다.
♻️ 프로필 한정 적용 예시
package com.team2.server.common.config import io.swagger.v3.oas.models.OpenAPI import io.swagger.v3.oas.models.info.Info import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Profile +@Profile("!prod") `@Configuration` class SwaggerConfig { `@Bean` fun openAPI(): OpenAPI = OpenAPI().info( Info() .title("Team2 API") .version("v1") .description("Team2 REST API"), ) }다만
@Profile은 OpenAPI 빈만 비활성화할 뿐이고, springdoc의 자동구성으로 등록되는/v3/api-docs·/swagger-ui는 여전히 살아 있습니다(빈이 없으면 기본 메타데이터로 동작). 엔드포인트 자체를 닫고 싶다면 위의springdoc.*.enabled=false프로퍼티를 함께 쓰셔야 합니다.참고로 빈 정의 자체는 별다른 문제 없이 잘 작성하셨고, Kotlin 코딩 컨벤션(스페이스 4칸 들여쓰기, 세미콜론 미사용, 파일 끝 개행)도 모두 준수하고 있어 LGTM 입니다.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main/kotlin/com/team2/server/common/config/SwaggerConfig.kt` around lines 8 - 18, SwaggerConfig's OpenAPI bean (class SwaggerConfig, fun openAPI()) currently exposes docs in all environments; to prevent accidental production exposure, restrict it to non-prod profiles (e.g., annotate SwaggerConfig with `@Profile`("dev","local") or `@Profile`("!prod")) AND add springdoc properties to your production config to fully disable endpoints (set springdoc.api-docs.enabled=false and springdoc.swagger-ui.enabled=false in application-prod.yml); remember `@Profile` only disables the bean, so include the prod properties to close /v3/api-docs and /swagger-ui endpoints as well.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@build.gradle.kts`:
- Line 34: Update the springdoc-openapi dependency version from 3.0.0 to 3.0.3
by modifying the implementation(...) declaration (the existing
org.springdoc:springdoc-openapi-starter-webmvc-ui entry) to use version 3.0.3;
after updating, rebuild and run the app and verify that the
/swagger-ui/index.html and /v3/api-docs endpoints load correctly to confirm
compatibility with Spring Boot 4 / Jackson 3.
---
Nitpick comments:
In `@src/main/kotlin/com/team2/server/common/config/SwaggerConfig.kt`:
- Around line 8-18: SwaggerConfig's OpenAPI bean (class SwaggerConfig, fun
openAPI()) currently exposes docs in all environments; to prevent accidental
production exposure, restrict it to non-prod profiles (e.g., annotate
SwaggerConfig with `@Profile`("dev","local") or `@Profile`("!prod")) AND add
springdoc properties to your production config to fully disable endpoints (set
springdoc.api-docs.enabled=false and springdoc.swagger-ui.enabled=false in
application-prod.yml); remember `@Profile` only disables the bean, so include the
prod properties to close /v3/api-docs and /swagger-ui endpoints as well.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: bfb4f8b2-2406-4f79-8b16-19c9af46a5fa
📒 Files selected for processing (3)
build.gradle.ktssrc/main/kotlin/com/team2/server/common/config/SwaggerConfig.ktsrc/main/resources/application.yml
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
🔗 Issue
💬 Context
API 문서화를 위해 Swagger UI를 도입합니다. 현재 프로젝트에 API 명세를 확인할 수 있는 도구가 없어 개발 및 협업 시 엔드포인트 확인이 불편한 상황이었습니다. SpringDoc OpenAPI 3.0 기반의 Swagger UI를 추가하여
/swagger-ui/index.html에서 API 명세를 실시간으로 확인할 수 있도록 합니다.🛠 Changes
springdoc-openapi-starter-webmvc-ui:3.0.0의존성 추가 (Spring Boot 4.x 호환)SwaggerConfig설정 클래스 추가 (OpenAPI info 정의)/swagger-ui/index.html/v3/api-docs👀 Review Focus
✅ Check List
Summary by CodeRabbit
릴리스 노트