Skip to content

Commit

Permalink
[MERGE] #152 - 스웨거 연동
Browse files Browse the repository at this point in the history
[FEAT] #152 - 스웨거 연동
  • Loading branch information
seokbeom00 authored Oct 7, 2024
2 parents 2b52fae + 92a9525 commit 49821aa
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ dependencies {

// Redisson
implementation "org.redisson:redisson:3.29.0"

// SWAGER
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0'
}

ext {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.sopt.seonyakServer;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.servers.Server;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@OpenAPIDefinition(servers = {@Server(url = "https://api.seonyak.com", description = "product seonyak server")})
@SpringBootApplication
@EnableScheduling
public class SeonyakServerApplication {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public class SecurityConfig {
"/actuator/health",
"/v3/api-docs/**",
"/swagger-ui/**",
"/swagger-ui.html",
"/swagger-resources/**",
"swagger-ui/index.html"
};

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.sopt.seonyakServer.global.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 openAPI() {
Info info = new Info()
.title("SEONYAK Swagger")
.description("SEONYAK Docs")
.version("1.0.0.");

// jwt에 대한 SecurityScheme 설정, Swagger-ui에서 token 인증이 가능해짐
String jwtSchemeName = "jwtAuth";
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("/"))
.addSecurityItem(securityRequirement)
.components(components)
.info(info);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
Expand All @@ -27,6 +28,9 @@ public void configureMessageConverters(List<HttpMessageConverter<?>> converters)
// 기존 컨버터들을 모두 제거 (외부 라이브러리의 코틀린 컨버터와 충돌을 피하기 위함)
converters.clear();

// Swagger M7 ByteArrayHttpMessageConverter (add
converters.add(new ByteArrayHttpMessageConverter());

// Jackson 라이브러리를 사용하는 컨버터 추가
converters.add(new MappingJackson2HttpMessageConverter());
}
Expand Down

0 comments on commit 49821aa

Please sign in to comment.