From f9d12f0602a0d8003948c617b4c8e180af3096b7 Mon Sep 17 00:00:00 2001 From: Park Yun Chan Date: Mon, 24 Jun 2024 17:24:08 +0900 Subject: [PATCH 1/3] =?UTF-8?q?chore:=20SwaggerConfig=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 ++ .../stonebed/global/config/SwaggerConfig.java | 32 +++++++++++++++++++ src/main/resources/application.yml | 15 +++++++++ 3 files changed, 49 insertions(+) create mode 100644 src/main/java/com/depromeet/stonebed/global/config/SwaggerConfig.java diff --git a/build.gradle b/build.gradle index 8d00cdf0..dc3ada1d 100644 --- a/build.gradle +++ b/build.gradle @@ -30,6 +30,8 @@ dependencies { // Actuator implementation 'org.springframework.boot:spring-boot-starter-actuator' + // Swagger + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0' compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.h2database:h2' diff --git a/src/main/java/com/depromeet/stonebed/global/config/SwaggerConfig.java b/src/main/java/com/depromeet/stonebed/global/config/SwaggerConfig.java new file mode 100644 index 00000000..8c5af99b --- /dev/null +++ b/src/main/java/com/depromeet/stonebed/global/config/SwaggerConfig.java @@ -0,0 +1,32 @@ +package com.depromeet.stonebed.global.config; + +import org.springdoc.core.models.GroupedOpenApi; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; + +@Configuration +public class SwaggerConfig { + + // OpenAPI Bean 설정 + @Bean + public OpenAPI openAPI() { + return new OpenAPI() + .info(new Info() + .title("WalWal 프로젝트 API 문서화") + .version("1.0") + .description("WalWal 프로젝트의 Swagger UI 화면입니다.")); + } + + // GroupedOpenApi Bean 설정 + @Bean + public GroupedOpenApi groupedOpenApi() { + String[] paths = {"/api/v1/**"}; + String[] packagesToScan = {"com.depromeet.stonebed"}; + return GroupedOpenApi.builder().group("WalWal API") + .pathsToMatch(paths) + .packagesToScan(packagesToScan) + .build(); + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 5b4a8805..d9be7858 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -15,3 +15,18 @@ management: endpoint: health: enabled: true + +springdoc: + api-docs: + path: /api-docs + groups: + enabled: true + swagger-ui: + enabled: true + groups-order: ASC + tags-sorter: alpha + operations-sorter: alpha + display-request-duration: true + doc-expansion: none + cache: + disabled: true From 788e4bae7a0bf6b9aa7e19226dececec91c44cf5 Mon Sep 17 00:00:00 2001 From: Park Yun Chan Date: Tue, 25 Jun 2024 13:21:47 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20Api=20path=20versioning=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=20=EB=B0=8F=20SwaggerConfig=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stonebed/global/config/SwaggerConfig.java | 11 +++++++---- src/main/resources/application.yml | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/depromeet/stonebed/global/config/SwaggerConfig.java b/src/main/java/com/depromeet/stonebed/global/config/SwaggerConfig.java index 8c5af99b..91a0eaa4 100644 --- a/src/main/java/com/depromeet/stonebed/global/config/SwaggerConfig.java +++ b/src/main/java/com/depromeet/stonebed/global/config/SwaggerConfig.java @@ -1,13 +1,19 @@ package com.depromeet.stonebed.global.config; import org.springdoc.core.models.GroupedOpenApi; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; + import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; @Configuration public class SwaggerConfig { + private static final String packagesToScan = "com.depromeet.stonebed"; + + @Value("${api.version}") + private String apiVersion; // OpenAPI Bean 설정 @Bean @@ -15,17 +21,14 @@ public OpenAPI openAPI() { return new OpenAPI() .info(new Info() .title("WalWal 프로젝트 API 문서화") - .version("1.0") + .version(apiVersion) .description("WalWal 프로젝트의 Swagger UI 화면입니다.")); } // GroupedOpenApi Bean 설정 @Bean public GroupedOpenApi groupedOpenApi() { - String[] paths = {"/api/v1/**"}; - String[] packagesToScan = {"com.depromeet.stonebed"}; return GroupedOpenApi.builder().group("WalWal API") - .pathsToMatch(paths) .packagesToScan(packagesToScan) .build(); } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index d9be7858..c55888eb 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -30,3 +30,6 @@ springdoc: doc-expansion: none cache: disabled: true + +api: + version: "0.0.1" From 7866e53d6199d098bad85efdbd0162fb2482048d Mon Sep 17 00:00:00 2001 From: Park Yun Chan Date: Tue, 25 Jun 2024 13:39:29 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=EC=83=81=EC=88=98=20=EC=BB=A8?= =?UTF-8?q?=EB=B2=A4=EC=85=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/depromeet/stonebed/global/config/SwaggerConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/depromeet/stonebed/global/config/SwaggerConfig.java b/src/main/java/com/depromeet/stonebed/global/config/SwaggerConfig.java index 91a0eaa4..90a37c62 100644 --- a/src/main/java/com/depromeet/stonebed/global/config/SwaggerConfig.java +++ b/src/main/java/com/depromeet/stonebed/global/config/SwaggerConfig.java @@ -10,7 +10,7 @@ @Configuration public class SwaggerConfig { - private static final String packagesToScan = "com.depromeet.stonebed"; + private static final String PACKAGES_TO_SCAN = "com.depromeet.stonebed"; @Value("${api.version}") private String apiVersion; @@ -29,7 +29,7 @@ public OpenAPI openAPI() { @Bean public GroupedOpenApi groupedOpenApi() { return GroupedOpenApi.builder().group("WalWal API") - .packagesToScan(packagesToScan) + .packagesToScan(PACKAGES_TO_SCAN) .build(); } }