SwaggerConfig.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package com.yihu.jw.config;
  2. import com.yihu.jw.restmodel.base.BaseContants;
  3. import org.springframework.context.annotation.Bean;
  4. import org.springframework.context.annotation.ComponentScan;
  5. import org.springframework.context.annotation.Configuration;
  6. import springfox.documentation.service.ApiInfo;
  7. import springfox.documentation.spi.DocumentationType;
  8. import springfox.documentation.spring.web.plugins.Docket;
  9. import springfox.documentation.swagger2.annotations.EnableSwagger2;
  10. import static com.google.common.base.Predicates.or;
  11. import static springfox.documentation.builders.PathSelectors.regex;
  12. @Configuration
  13. @EnableSwagger2
  14. @ComponentScan("com.yihu.jw.*.controller")
  15. public class SwaggerConfig {
  16. public static final String PUBLIC_API = "Default";
  17. public static final String Base_API = "JwBase";
  18. @Bean
  19. public Docket publicAPI() {
  20. return new Docket(DocumentationType.SWAGGER_2)
  21. .groupName(PUBLIC_API)
  22. .useDefaultResponseMessages(false)
  23. .forCodeGeneration(false)
  24. .pathMapping("/")
  25. .select()
  26. .paths(or(
  27. regex("/patient/.*")
  28. , regex("/"+ BaseContants.Function.api_common+"/.*")
  29. ,regex("/"+BaseContants.Wechat.api_common+"/.*")
  30. ,regex("/"+BaseContants.WxAccessToken.api_common+"/.*")
  31. ,regex("/"+BaseContants.WxMenu.api_common+"/.*")
  32. ,regex("/"+BaseContants.WxTemplate.api_common+"/.*")
  33. ))
  34. .build()
  35. .apiInfo(publicApiInfo());
  36. }
  37. private ApiInfo publicApiInfo() {
  38. ApiInfo apiInfo = new ApiInfo("基卫2.0API",
  39. "基卫2.0API,提供基础卫生相关服务。",
  40. "1.0",
  41. "No terms of service",
  42. "wenfujian@jkzl.com",
  43. "The Apache License, Version 2.0",
  44. "http://www.apache.org/licenses/LICENSE-2.0.html"
  45. );
  46. return apiInfo;
  47. }
  48. @Bean
  49. public Docket jwBaseAPI() {
  50. return new Docket(DocumentationType.SWAGGER_2)
  51. .groupName(Base_API)
  52. .useDefaultResponseMessages(false)
  53. .forCodeGeneration(false)
  54. .pathMapping("/")
  55. .select()
  56. .paths(or(
  57. regex("/"+ BaseContants.Function.api_common+"/.*")
  58. ,regex("/"+ BaseContants.Saas.api_common+"/.*")
  59. ,regex("/"+ BaseContants.Module.api_common+"/.*")
  60. ))
  61. .build()
  62. .apiInfo(jwBaseApiInfo());
  63. }
  64. private ApiInfo jwBaseApiInfo() {
  65. ApiInfo apiInfo = new ApiInfo("基卫2.0API",
  66. "基卫2.0基础扩展API,提供基卫2.0基础扩展相关服务。",
  67. "1.0",
  68. "No terms of service",
  69. "wenfujian@jkzl.com",
  70. "The Apache License, Version 2.0",
  71. "http://www.apache.org/licenses/LICENSE-2.0.html"
  72. );
  73. return apiInfo;
  74. }
  75. }