Skip to content

Commit

Permalink
Merge pull request #225 from Sc0up/refactor-swagger-config
Browse files Browse the repository at this point in the history
[Freddie] SwaggerConfig 생성 후 관련 설정 이동
  • Loading branch information
Dae-Hwa authored Nov 27, 2021
2 parents 09950ba + 721d7a9 commit 1dd3f61
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 40 deletions.
28 changes: 0 additions & 28 deletions src/main/java/com/postsquad/scoup/ScoupApplication.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,14 @@
package com.postsquad.scoup;

import com.google.common.base.Predicates;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableSwagger2
@EnableJpaAuditing
@SpringBootApplication
public class ScoupApplication {

public static void main(String[] args) {
SpringApplication.run(ScoupApplication.class, args);
}

@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("Scoup")
.apiInfo(apiInfo())
.select()
.paths(Predicates.not(PathSelectors.regex("/error")))
.paths(PathSelectors.ant("/**"))
.build();
}

private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Scoup API Documentation")
.version("1.0")
.description("Scoup의 API 문서입니다.")
.build();
}
}
49 changes: 49 additions & 0 deletions src/main/java/com/postsquad/scoup/web/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.postsquad.scoup.web.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.hateoas.client.LinkDiscoverer;
import org.springframework.hateoas.client.LinkDiscoverers;
import org.springframework.hateoas.mediatype.collectionjson.CollectionJsonLinkDiscoverer;
import org.springframework.plugin.core.SimplePluginRegistry;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

@EnableSwagger2
@Configuration
public class SwaggerConfig {

@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("Scoup")
.apiInfo(apiInfo())
.select()
.paths(Predicates.not(PathSelectors.regex("/error")))
.paths(PathSelectors.ant("/**"))
.build();
}

private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Scoup API Documentation")
.version("1.0")
.description("Scoup의 API 문서입니다.")
.build();
}

@Bean
public LinkDiscoverers discoverers() {
List<LinkDiscoverer> plugins = new ArrayList<>();
plugins.add(new CollectionJsonLinkDiscoverer());
return new LinkDiscoverers(SimplePluginRegistry.create(plugins));
}
}
12 changes: 0 additions & 12 deletions src/main/java/com/postsquad/scoup/web/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.hateoas.client.LinkDiscoverer;
import org.springframework.hateoas.client.LinkDiscoverers;
import org.springframework.hateoas.mediatype.collectionjson.CollectionJsonLinkDiscoverer;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.http.codec.json.Jackson2JsonDecoder;
import org.springframework.plugin.core.SimplePluginRegistry;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
import org.springframework.web.reactive.function.client.WebClient;
Expand All @@ -21,7 +17,6 @@
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import reactor.netty.http.client.HttpClient;

import java.util.ArrayList;
import java.util.List;

@RequiredArgsConstructor
Expand Down Expand Up @@ -76,11 +71,4 @@ public void addInterceptors(InterceptorRegistry registry) {
.addPathPatterns("/**")
.excludePathPatterns(SIGNIN_PATH_TO_EXCLUDE);
}

@Bean
public LinkDiscoverers discoverers() {
List<LinkDiscoverer> plugins = new ArrayList<>();
plugins.add(new CollectionJsonLinkDiscoverer());
return new LinkDiscoverers(SimplePluginRegistry.create(plugins));
}
}

0 comments on commit 1dd3f61

Please sign in to comment.