From 07ce8a96e9aae22aa5668a5e4fc7534483148334 Mon Sep 17 00:00:00 2001 From: kjungw1025 Date: Thu, 25 Jul 2024 17:19:16 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Swagger=EC=97=90=20JWT=20=ED=86=A0?= =?UTF-8?q?=ED=81=B0=20=EC=9D=B8=EC=A6=9D=EC=9D=84=20=ED=95=A0=20=EC=88=98?= =?UTF-8?q?=20=EC=9E=88=EB=8A=94=20=ED=8E=B8=EC=9D=98=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/config/swagger/SwaggerConfig.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/wl2c/elswhereproductservice/global/config/swagger/SwaggerConfig.java b/src/main/java/com/wl2c/elswhereproductservice/global/config/swagger/SwaggerConfig.java index d96810b..32c75d5 100644 --- a/src/main/java/com/wl2c/elswhereproductservice/global/config/swagger/SwaggerConfig.java +++ b/src/main/java/com/wl2c/elswhereproductservice/global/config/swagger/SwaggerConfig.java @@ -2,13 +2,18 @@ import io.swagger.v3.oas.annotations.OpenAPIDefinition; import io.swagger.v3.oas.annotations.info.Info; +import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.security.SecurityScheme; import io.swagger.v3.oas.models.servers.Server; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import java.util.Collections; + @Configuration @RequiredArgsConstructor @@ -28,7 +33,14 @@ public class SwaggerConfig { @Bean public OpenAPI openAPI() { + SecurityScheme securityScheme = new SecurityScheme() + .type(SecurityScheme.Type.HTTP).scheme("bearer").bearerFormat("JWT") + .in(SecurityScheme.In.HEADER).name("Authorization"); + SecurityRequirement securityRequirement = new SecurityRequirement().addList("bearerAuth"); + return new OpenAPI() + .components(new Components().addSecuritySchemes("bearerAuth", securityScheme)) + .security(Collections.singletonList(securityRequirement)) .addServersItem(new Server().url(developmentServerUrl).description("개발 서버")) .addServersItem(new Server().url(localServerUrl).description("로컬 서버")); }