From 55b7c4d3c7a4a4600b4c3d7ac0e4952f06be0fb5 Mon Sep 17 00:00:00 2001 From: rlarltj123 Date: Thu, 18 Jul 2024 01:07:24 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Swagger=20UI=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=EC=9D=84=20=EC=B6=94=EA=B0=80=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 ++ .../global/config/docs/OpenApiConfig.java | 41 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/main/java/com/dnd/accompany/global/config/docs/OpenApiConfig.java diff --git a/build.gradle b/build.gradle index 4fc85d6..4919187 100644 --- a/build.gradle +++ b/build.gradle @@ -43,6 +43,9 @@ dependencies { annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta" annotationProcessor "jakarta.annotation:jakarta.annotation-api" annotationProcessor "jakarta.persistence:jakarta.persistence-api" + + // Swagger + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0' } tasks.named('test') { diff --git a/src/main/java/com/dnd/accompany/global/config/docs/OpenApiConfig.java b/src/main/java/com/dnd/accompany/global/config/docs/OpenApiConfig.java new file mode 100644 index 0000000..e746c7d --- /dev/null +++ b/src/main/java/com/dnd/accompany/global/config/docs/OpenApiConfig.java @@ -0,0 +1,41 @@ +package com.dnd.accompany.global.config.docs; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; + +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.security.SecurityScheme; +import io.swagger.v3.oas.models.servers.Server; + +@Configuration +@Profile({"local", "dev", "prod"}) +public class OpenApiConfig { + + @Bean + public OpenAPI openApi() { + Info info = new Info() + .title("DND API Document"); + + String jwtSchemeName = "Authorization"; + + SecurityRequirement securityRequirement = new SecurityRequirement().addList(jwtSchemeName); + + Components components = new Components() + .addSecuritySchemes(jwtSchemeName, new SecurityScheme() + .name(jwtSchemeName) + .type(SecurityScheme.Type.HTTP) + .scheme("Bearer") + .bearerFormat("JWT")); + + return new OpenAPI() + .addServersItem(new Server().url("/")) + .components(new Components()) + .addSecurityItem(securityRequirement) + .components(components) + .info(info); + } +}