Skip to content

Commit

Permalink
setup #38: springdoc 세팅
Browse files Browse the repository at this point in the history
  • Loading branch information
OldRabbit736 committed Nov 7, 2023
1 parent 3d0e393 commit e1d4c49
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ dependencies {
// log4j2
implementation 'org.springframework.boot:spring-boot-starter-log4j2'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml'

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

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ public class SecurityConfig {
private final AuthenticationEntryPoint authenticationEntryPoint;
private final AccessDeniedHandler accessDeniedHandler;

// SpringDocConfig의 Bean으로부터 받아오는 값
private final String swaggerPath;
private final String apiDocPath;

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests(authorizeHttpRequest -> authorizeHttpRequest
.requestMatchers("/api/**").permitAll()
.requestMatchers(swaggerPath).permitAll()
.requestMatchers(apiDocPath).permitAll()
.anyRequest().authenticated()
)
.headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.wanted.teamr.tastyfinder.api.config;

import lombok.RequiredArgsConstructor;
import org.springdoc.core.properties.SpringDocConfigProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor
public class SpringDocConfig {

private final SpringDocConfigProperties springDocConfigProperties;

/**
* swagger ui 웹 페이지 주소: /swagger-ui/index.html
* <p>
* swagger ui 웹 페이지 리소스(js, css 등) 주소: /swagger-ui/**
*
* @return swagger-ui 웹 페이지, 웹 페이지를 위한 리소스 모두를 포함하는 주소 반환
*/
@Bean(name = "swaggerPath")
public String getSwaggerPath() {
return "/swagger-ui/**";
}

/**
* api doc 주소: configuraiton file의 {springdoc.api-docs.path}
* <p>
* swagger-ui에서 요청하는 리소스(swagger-config 등) 주소: {springdoc.api-docs.path}/**
*
* @return api doc 주소와 그 외 swagger-ui에서 요청하는 리소스 모두를 포함하는 주소 반환
*/
@Bean(name = "apiDocPath")
public String getApiDocPath() {
return springDocConfigProperties.getApiDocs().getPath() + "/**";
}

}
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ spring:
- private/application-private.yml
- redis.yml
- sgg-csv-config.yml
- springdoc-config.yml

logging:
level:
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/springdoc-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
springdoc:
api-docs:
path: /api-docs

0 comments on commit e1d4c49

Please sign in to comment.