From fe2f5012aa5644918d22e1e382deece44487da0d Mon Sep 17 00:00:00 2001 From: Sejin Park <95167215+sejineer@users.noreply.github.com> Date: Tue, 2 Jan 2024 09:51:26 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Swagger=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(#27)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 +- .../global/config/OpenApiConfig.java | 44 +++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/finfellows/global/config/OpenApiConfig.java diff --git a/build.gradle b/build.gradle index ca14d4d..1c83357 100644 --- a/build.gradle +++ b/build.gradle @@ -33,8 +33,8 @@ dependencies { runtimeOnly 'com.mysql:mysql-connector-j' //Swagger, RestDocs - implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.1.0' - testImplementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-api', version: '2.1.0' + implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.3.0' + testImplementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-api', version: '2.3.0' //jwt implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.5' diff --git a/src/main/java/com/finfellows/global/config/OpenApiConfig.java b/src/main/java/com/finfellows/global/config/OpenApiConfig.java new file mode 100644 index 0000000..aa656b1 --- /dev/null +++ b/src/main/java/com/finfellows/global/config/OpenApiConfig.java @@ -0,0 +1,44 @@ +package com.finfellows.global.config; + +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.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.License; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.security.SecurityScheme; + +@Configuration +public class OpenApiConfig { + + private final String securitySchemeName = "bearerAuth"; + + @Bean + public OpenAPI openAPI(@Value("OpenAPI") String appVersion) { + Info info = new Info().title("FinFellow API").version(appVersion) + .description("FinFellow 웹 애플리케이션 API입니다.") + .termsOfService("http://swagger.io/terms/") + .contact(new Contact().name("FinFellow").email("finfellow2023@gmail.com")) + .license(new License().name("Apache License Version 2.0") + .url("http://www.apache.org/licenses/LICENSE-2.0")); + + return new OpenAPI() + .addSecurityItem(new SecurityRequirement().addList(securitySchemeName)) + .components( + new Components() + .addSecuritySchemes(securitySchemeName, + new SecurityScheme() + .name(securitySchemeName) + .type(SecurityScheme.Type.HTTP) + .scheme("bearer") + .bearerFormat("JWT") + ) + ) + .info(info); + } + +} \ No newline at end of file