Skip to content

Commit

Permalink
Improved swagger configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
dartartem committed May 28, 2021
1 parent fe3b7c0 commit 14dbb45
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 14dbb45

Please sign in to comment.