From e0e868a2821305ea7200a12cf0dbd9b37ea10396 Mon Sep 17 00:00:00 2001 From: sohot8653 Date: Wed, 13 Aug 2025 13:53:15 +0900 Subject: [PATCH] =?UTF-8?q?[Swagger=20=EC=B4=88=EA=B8=B0=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 26 +++++++++++++++- build.gradle | 3 ++ .../global/config/SwaggerConfig.java | 31 +++++++++++++++++++ src/main/resources/application.properties | 8 +++++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/bio/bio_backend/global/config/SwaggerConfig.java diff --git a/README.md b/README.md index dc03b06..cfbab31 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ - **Security**: Spring Security + JWT - **Build Tool**: Gradle - **Container**: Docker + Kubernetes +- **API Documentation**: Swagger (SpringDoc OpenAPI) ## 개발 가이드 @@ -31,7 +32,30 @@ src/main/java/com/bio/bio_backend/ └── BioBackendApplication.java ``` -### 2. 트랜잭션 관리 +### 2. API 문서화 (Swagger) + +#### Swagger UI 접속 + +- **URL**: `http://localhost:8080/service/swagger-ui.html` +- **API Docs**: `http://localhost:8080/service/api-docs` + +#### 주요 어노테이션 + +```java +@Tag(name = "Member", description = "회원 관리 API") +@Operation(summary = "회원 가입", description = "새로운 회원을 등록합니다.") +@ApiResponses(value = { + @ApiResponse(responseCode = "201", description = "회원 가입 성공"), + @ApiResponse(responseCode = "400", description = "잘못된 요청 데이터") +}) +``` + +#### 설정 파일 + +- **SwaggerConfig.java**: OpenAPI 기본 정보 설정 +- **application.properties**: Swagger UI 커스터마이징 + +### 3. 트랜잭션 관리 #### 기본 설정 diff --git a/build.gradle b/build.gradle index 5753559..ccc0e45 100644 --- a/build.gradle +++ b/build.gradle @@ -61,6 +61,9 @@ dependencies { // p6spy implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.0' + + // SpringDoc OpenAPI (Swagger) + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.9' } tasks.named('test') { diff --git a/src/main/java/com/bio/bio_backend/global/config/SwaggerConfig.java b/src/main/java/com/bio/bio_backend/global/config/SwaggerConfig.java new file mode 100644 index 0000000..1ef3edb --- /dev/null +++ b/src/main/java/com/bio/bio_backend/global/config/SwaggerConfig.java @@ -0,0 +1,31 @@ +package com.bio.bio_backend.global.config; + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.License; +import io.swagger.v3.oas.models.servers.Server; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.List; + +@Configuration +public class SwaggerConfig { + + @Bean + public OpenAPI openAPI() { + return new OpenAPI() + .info(new Info() + .title("대상 미생물 분석 시스템 Backend API") + .description("대상 미생물 분석 시스템 Backend 서비스의 REST API 문서") + .version("v1.0.0") + .license(new License() + .name("STAM License") + .url("https://stam.kr/"))) + .servers(List.of( + new Server().url("http://localhost:8080/service").description("Local Development Server"), + new Server().url("https://api.bio.com/service").description("Production Server") + )); + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index cfa157e..09f9612 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -54,3 +54,11 @@ token.expiration_time_access=180000 token.expiration_time_refresh=604800000 token.secret_key= c3RhbV9qd3Rfc2VjcmV0X3Rva2Vuc3RhbV9qd3Rfc2VjcmV0X3Rva2Vu +# Swagger 설정 +springdoc.api-docs.path=/api-docs +springdoc.swagger-ui.path=/swagger-ui.html +springdoc.swagger-ui.operationsSorter=method +springdoc.swagger-ui.tagsSorter=alpha +springdoc.swagger-ui.doc-expansion=none +springdoc.swagger-ui.disable-swagger-default-url=true +