From 14dbb45de3c8e7b86786c0ab57183ad44b8a23e1 Mon Sep 17 00:00:00 2001 From: Artem Sidorkin Date: Fri, 28 May 2021 11:03:31 +0300 Subject: [PATCH] Improved swagger configuration --- .../CommonSwaggerAutoConfiguration.java | 22 ++------------- .../swagger/CommonSwaggerConfiguration.java | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 eventuate-util-spring-swagger/src/main/java/io/eventuate/util/spring/swagger/CommonSwaggerConfiguration.java diff --git a/eventuate-util-spring-swagger/src/main/java/io/eventuate/util/spring/swagger/CommonSwaggerAutoConfiguration.java b/eventuate-util-spring-swagger/src/main/java/io/eventuate/util/spring/swagger/CommonSwaggerAutoConfiguration.java index c8e6fb2..126468d 100644 --- a/eventuate-util-spring-swagger/src/main/java/io/eventuate/util/spring/swagger/CommonSwaggerAutoConfiguration.java +++ b/eventuate-util-spring-swagger/src/main/java/io/eventuate/util/spring/swagger/CommonSwaggerAutoConfiguration.java @@ -1,30 +1,12 @@ package io.eventuate.util.spring.swagger; -import com.fasterxml.classmate.TypeResolver; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.http.ResponseEntity; -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.swagger2.annotations.EnableSwagger2; +import org.springframework.context.annotation.Import; @Configuration -@EnableSwagger2 @ConditionalOnBean(EventuateSwaggerConfig.class) +@Import(CommonSwaggerConfiguration.class) public class CommonSwaggerAutoConfiguration { - @Bean - public Docket api(EventuateSwaggerConfig eventuateSwaggerConfig, - TypeResolver typeResolver) { - - return new Docket(DocumentationType.SWAGGER_2) - .select() - .apis(RequestHandlerSelectors.basePackage(eventuateSwaggerConfig.requestHandlerSelectorsBasePackage())) - .build() - .pathMapping("/") - .genericModelSubstitutes(ResponseEntity.class) - .useDefaultResponseMessages(false); - } } diff --git a/eventuate-util-spring-swagger/src/main/java/io/eventuate/util/spring/swagger/CommonSwaggerConfiguration.java b/eventuate-util-spring-swagger/src/main/java/io/eventuate/util/spring/swagger/CommonSwaggerConfiguration.java new file mode 100644 index 0000000..58882c1 --- /dev/null +++ b/eventuate-util-spring-swagger/src/main/java/io/eventuate/util/spring/swagger/CommonSwaggerConfiguration.java @@ -0,0 +1,28 @@ +package io.eventuate.util.spring.swagger; + +import com.fasterxml.classmate.TypeResolver; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.ResponseEntity; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 +public class CommonSwaggerConfiguration { + + @Bean + public Docket api(EventuateSwaggerConfig eventuateSwaggerConfig, + TypeResolver typeResolver) { + + return new Docket(DocumentationType.SWAGGER_2) + .select() + .apis(RequestHandlerSelectors.basePackage(eventuateSwaggerConfig.requestHandlerSelectorsBasePackage())) + .build() + .pathMapping("/") + .genericModelSubstitutes(ResponseEntity.class) + .useDefaultResponseMessages(false); + } +}