Guest User

Untitled

a guest
Mar 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. import com.google.common.base.Predicate;
  2. import com.google.common.base.Predicates;
  3. import org.springframework.context.annotation.Bean;
  4. import org.springframework.context.annotation.Configuration;
  5. import springfox.documentation.builders.ApiInfoBuilder;
  6. import springfox.documentation.builders.PathSelectors;
  7. import springfox.documentation.builders.RequestHandlerSelectors;
  8. import springfox.documentation.service.ApiInfo;
  9. import springfox.documentation.spi.DocumentationType;
  10. import springfox.documentation.spring.web.plugins.Docket;
  11. import springfox.documentation.swagger2.annotations.EnableSwagger2;
  12.  
  13. @Configuration
  14. @EnableSwagger2
  15. public class SwaggerConfig {
  16.  
  17. @Bean
  18. public Docket api() {
  19. return new Docket(DocumentationType.SWAGGER_2)
  20. .apiInfo(apiInfo())
  21. .select()
  22. .apis(RequestHandlerSelectors.any())
  23. .paths(paths())
  24. .build();
  25. }
  26.  
  27. // Describe your apis
  28. private ApiInfo apiInfo() {
  29. return new ApiInfoBuilder()
  30. .title("Swagger Sample APIs")
  31. .description("This page lists all the rest apis for Swagger Sample App.")
  32. .version("1.0-SNAPSHOT")
  33. .build();
  34. }
  35.  
  36. // Only select apis that matches the given Predicates.
  37. private Predicate<String> paths() {
  38. // Match all paths except /error
  39. return Predicates.and(
  40. PathSelectors.regex("/.*"),
  41. Predicates.not(PathSelectors.regex("/error.*"))
  42. );
  43. }
  44. }
Add Comment
Please, Sign In to add comment