Skip to content

[Chore] SpringDoc Swagger UI 설정 추가 - #24

Merged
suker80 merged 1 commit into
developfrom
chore/swagger-setup
Apr 25, 2026
Merged

[Chore] SpringDoc Swagger UI 설정 추가#24
suker80 merged 1 commit into
developfrom
chore/swagger-setup

Conversation

@suker80

@suker80 suker80 commented Apr 25, 2026

Copy link
Copy Markdown
Collaborator

🔗 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 접속 경로: /swagger-ui/index.html
  • API 문서 JSON: /v3/api-docs

👀 Review Focus

  • springdoc 3.0.0 버전이 Spring Boot 4.0.5와 호환되는지 확인
  • 운영 환경에서 Swagger UI 비활성화 필요 여부 논의

✅ Check List

  • Assignees 등록
  • Label 등록
  • CI 통과 확인

Comment prefix — P1: 필수 반영 / P2: 적극 고려 / P3: 사소한 의견

Summary by CodeRabbit

릴리스 노트

  • New Features
    • API 자동 문서화 기능 추가됨. 애플리케이션의 REST API가 Swagger UI를 통해 시각적으로 확인 및 테스트 가능하도록 설정되었습니다.

@suker80 suker80 self-assigned this Apr 25, 2026
@github-actions
github-actions Bot requested review from eundeang and lydbsdud April 25, 2026 08:29
@github-actions github-actions Bot added the 🗑️ CHORE 빌드 수정, 패키지 수정 등 label Apr 25, 2026
@coderabbitai

coderabbitai Bot commented Apr 25, 2026

Copy link
Copy Markdown

Walkthrough

SpringDoc OpenAPI UI 의존성을 프로젝트에 추가하고, API 메타데이터(제목, 버전, 설명)를 설정하는 OpenAPI 빈을 등록하는 Swagger 설정을 구현했습니다. 파일 형식도 정규화했습니다.

Changes

Cohort / File(s) Summary
Swagger 의존성 추가
build.gradle.kts
springdoc-openapi-starter-webmvc-ui 3.0.0 의존성을 런타임 클래스패스에 추가했습니다.
Swagger 설정
src/main/kotlin/com/team2/server/common/config/SwaggerConfig.kt
@configuration 클래스를 신규 생성하여 OpenAPI 빈을 등록했습니다. Info 객체를 통해 API 제목, 버전, 설명 메타데이터를 정의합니다.
파일 형식 정규화
src/main/resources/application.yml
파일 끝에 줄바꿈 문자를 추가하여 표준 형식을 준수했습니다.

🔍 리뷰 의견

SwaggerConfig.kt에 대한 제안:

현재 Info 객체에 설정된 메타데이터가 하드코딩되어 있습니다. 애플리케이션의 버전이 변경될 때마다 코드를 수정해야 하는 상황을 피하기 위해, 다음과 같이 application.yml에서 속성을 읽어오는 방식을 고려해보시는 것을 권장드립니다:

`@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)
            )
    }
}

이렇게 하면 application.yml에서 중앙집중식으로 메타데이터를 관리할 수 있습니다.


Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목이 변경사항의 핵심을 명확하게 요약하고 있습니다. SpringDoc Swagger UI 설정 추가라는 주요 변경사항을 정확하게 나타냅니다.
Linked Issues check ✅ Passed 모든 연결된 이슈 #23의 요구사항이 충족되었습니다. springdoc-openapi-starter-webmvc-ui 의존성 추가, SwaggerConfig 설정 클래스 작성이 완료되었습니다.
Out of Scope Changes check ✅ Passed 모든 변경사항이 Swagger UI 설정 추가라는 목표와 직접적으로 관련이 있으며, 범위를 벗어난 변경은 없습니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/swagger-setup

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown

📊 테스트 커버리지 리포트

Overall Project 36.11%
Files changed 100% 🍏

File Coverage
SwaggerConfig.kt 100% 🍏

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0b3ef5e and c469da2.

📒 Files selected for processing (3)
  • build.gradle.kts
  • src/main/kotlin/com/team2/server/common/config/SwaggerConfig.kt
  • src/main/resources/application.yml

Comment thread build.gradle.kts
@suker80
suker80 merged commit 09df564 into develop Apr 25, 2026
9 checks passed
@suker80
suker80 deleted the chore/swagger-setup branch April 25, 2026 08:34
@claude

claude Bot commented Apr 25, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🗑️ CHORE 빌드 수정, 패키지 수정 등

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Chore] Swagger(SpringDoc) 설정 추가

2 participants