From f38b85f29b3b9fda3ce085a5064b70b03d179954 Mon Sep 17 00:00:00 2001 From: DDonghyeo Date: Tue, 28 May 2024 00:07:57 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8feat=20:=20Swagger=20Config=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notiservice/config/SwaggerConfig.java | 29 +++++++++++--- .../userservice/config/SwaggerConfig.java | 40 +++++++++++++++++++ .../weatherservice/swagger/SwaggerConfig.java | 27 +++++++++++++ 3 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 user-service/src/main/java/com/waither/userservice/config/SwaggerConfig.java create mode 100644 weather-service/src/main/java/com/waither/weatherservice/swagger/SwaggerConfig.java diff --git a/noti-service/src/main/java/com/waither/notiservice/config/SwaggerConfig.java b/noti-service/src/main/java/com/waither/notiservice/config/SwaggerConfig.java index 4fc2f6c8..170601e1 100644 --- a/noti-service/src/main/java/com/waither/notiservice/config/SwaggerConfig.java +++ b/noti-service/src/main/java/com/waither/notiservice/config/SwaggerConfig.java @@ -3,6 +3,8 @@ 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; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -11,13 +13,28 @@ public class SwaggerConfig { @Bean - public OpenAPI springShopOpenAPI() { + public OpenAPI waitherAPI() { + Info info = new Info() + .title("Waither Notification API Docs") + .description("Waither Notification Service API 명세서입니다.") + .version("1.0.0"); + + String jwtSchemeName = "accessToken"; + // API 요청헤더에 인증정보 포함 + SecurityRequirement securityRequirement = new SecurityRequirement().addList(jwtSchemeName); + + // SecuritySchemes 등록 + Components components = new Components() + .addSecuritySchemes(jwtSchemeName, new SecurityScheme() + .name(jwtSchemeName) + .type(SecurityScheme.Type.HTTP) // HTTP 방식 + .scheme("bearer") + .bearerFormat("JWT")); + return new OpenAPI() - .components(new Components()) .addServersItem(new Server().url("/")) - .info(new Info().title("noti-service API") - .description("Waither noti-service API 명세서입니다.") - .version("v0.0.1") - ); + .info(info) + .addSecurityItem(securityRequirement) + .components(components); } } diff --git a/user-service/src/main/java/com/waither/userservice/config/SwaggerConfig.java b/user-service/src/main/java/com/waither/userservice/config/SwaggerConfig.java new file mode 100644 index 00000000..a60f0b21 --- /dev/null +++ b/user-service/src/main/java/com/waither/userservice/config/SwaggerConfig.java @@ -0,0 +1,40 @@ +package com.waither.userservice.config; + +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; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class SwaggerConfig { + + @Bean + public OpenAPI waitherAPI() { + Info info = new Info() + .title("Waither User API Docs") + .description("Waither User Service API 명세서입니다.") + .version("1.0.0"); + + String jwtSchemeName = "accessToken"; + // API 요청헤더에 인증정보 포함 + SecurityRequirement securityRequirement = new SecurityRequirement().addList(jwtSchemeName); + + // SecuritySchemes 등록 + Components components = new Components() + .addSecuritySchemes(jwtSchemeName, new SecurityScheme() + .name(jwtSchemeName) + .type(SecurityScheme.Type.HTTP) // HTTP 방식 + .scheme("bearer") + .bearerFormat("JWT")); + + return new OpenAPI() + .addServersItem(new Server().url("/")) + .info(info) + .addSecurityItem(securityRequirement) + .components(components); + } +} diff --git a/weather-service/src/main/java/com/waither/weatherservice/swagger/SwaggerConfig.java b/weather-service/src/main/java/com/waither/weatherservice/swagger/SwaggerConfig.java new file mode 100644 index 00000000..71c3e872 --- /dev/null +++ b/weather-service/src/main/java/com/waither/weatherservice/swagger/SwaggerConfig.java @@ -0,0 +1,27 @@ +package com.waither.weatherservice.swagger; + +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; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class SwaggerConfig { + + @Bean + public OpenAPI waitherAPI() { + Info info = new Info() + .title("Waither Weather API Docs") + .description("Waither Weather Service API 명세서입니다.") + .version("1.0.0"); + + + return new OpenAPI() + .addServersItem(new Server().url("/")) + .info(info); + } +}