SwaggerConfig.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package com.yihu.jw.config;
  2. import com.yihu.jw.restmodel.base.base.BaseContants;
  3. import com.yihu.jw.restmodel.wlyy.agreement.WlyyAgreementContants;
  4. import com.yihu.jw.restmodel.wlyy.patient.WlyyPatientContants;
  5. import com.yihu.jw.restmodel.wx.WxContants;
  6. import org.springframework.context.annotation.Bean;
  7. import org.springframework.context.annotation.ComponentScan;
  8. import org.springframework.context.annotation.Configuration;
  9. import springfox.documentation.service.ApiInfo;
  10. import springfox.documentation.spi.DocumentationType;
  11. import springfox.documentation.spring.web.plugins.Docket;
  12. import springfox.documentation.swagger2.annotations.EnableSwagger2;
  13. import static com.google.common.base.Predicates.or;
  14. import static springfox.documentation.builders.PathSelectors.regex;
  15. @Configuration
  16. @EnableSwagger2
  17. @ComponentScan("com.yihu.jw.**")
  18. public class SwaggerConfig {
  19. public static final String PUBLIC_API = "Default";
  20. public static final String Base_API = "JwBase";
  21. public static final String Wlyy_API = "Wlyy";
  22. @Bean
  23. public Docket publicAPI() {
  24. return new Docket(DocumentationType.SWAGGER_2)
  25. .groupName(PUBLIC_API)
  26. .useDefaultResponseMessages(false)
  27. .forCodeGeneration(false)
  28. .pathMapping("/")
  29. .select()
  30. .paths(or(
  31. regex("/patient/.*")
  32. , regex("/"+ BaseContants.Function.api_common+"/.*")
  33. ,regex("/"+ WxContants.Wechat.api_common+"/.*")
  34. ,regex("/"+WxContants.WxAccessToken.api_common+"/.*")
  35. ,regex("/"+WxContants.WxMenu.api_common+"/.*")
  36. ,regex("/"+WxContants.WxTemplate.api_common+"/.*")
  37. ,regex("/"+WxContants.WxGraphicMessage.api_common+"/.*")
  38. ))
  39. .build()
  40. .apiInfo(publicApiInfo());
  41. }
  42. private ApiInfo publicApiInfo() {
  43. ApiInfo apiInfo = new ApiInfo("基卫2.0API",
  44. "基卫2.0API,提供基础卫生相关服务。",
  45. "1.0",
  46. "No terms of service",
  47. "wenfujian@jkzl.com",
  48. "The Apache License, Version 2.0",
  49. "http://www.apache.org/licenses/LICENSE-2.0.html"
  50. );
  51. return apiInfo;
  52. }
  53. @Bean
  54. public Docket wlyyAPI() {
  55. return new Docket(DocumentationType.SWAGGER_2)
  56. .groupName(Wlyy_API)
  57. .useDefaultResponseMessages(false)
  58. .forCodeGeneration(false)
  59. .pathMapping("/")
  60. .select()
  61. .paths(or(
  62. regex("/" + WlyyAgreementContants.Agreement.api_common + "/.*")
  63. , regex("/" + WlyyAgreementContants.AgreementKpi.api_common + "/.*")
  64. , regex("/" + WlyyAgreementContants.AgreementKpiLog.api_common + "/.*")
  65. , regex("/" + WlyyAgreementContants.SignFamily.api_common + "/.*")
  66. , regex("/" + WlyyPatientContants.Advertisement.api_common + "/.*")
  67. ))
  68. .build()
  69. .apiInfo(wlyyApiInfo());
  70. }
  71. private ApiInfo wlyyApiInfo() {
  72. ApiInfo wlyyInfo = new ApiInfo("基卫2.0API",
  73. "基卫2.0API,提供基础卫生相关服务。",
  74. "1.0",
  75. "No terms of service",
  76. "wenfujian@jkzl.com",
  77. "The Apache License, Version 2.0",
  78. "http://www.apache.org/licenses/LICENSE-2.0.html"
  79. );
  80. return wlyyInfo;
  81. }
  82. @Bean
  83. public Docket jwBaseAPI() {
  84. return new Docket(DocumentationType.SWAGGER_2)
  85. .groupName(Base_API)
  86. .useDefaultResponseMessages(false)
  87. .forCodeGeneration(false)
  88. .pathMapping("/")
  89. .select()
  90. .paths(or(
  91. regex("/"+ BaseContants.Function.api_common+"/.*")
  92. ,regex("/"+ BaseContants.Saas.api_common+"/.*")
  93. ,regex("/"+ BaseContants.Module.api_common+"/.*")
  94. ,regex("/"+ WxContants.Wechat.api_common+"/.*")
  95. ,regex("/"+ WxContants.WxTemplate.api_common+"/.*")
  96. ,regex("/"+ WxContants.WxGraphicMessage.api_common+"/.*")
  97. ,regex("/"+ WxContants.WxMenu.api_common+"/.*")
  98. ,regex("/"+ WxContants.WxAccessToken.api_common+"/.*")
  99. ))
  100. .build()
  101. .apiInfo(jwBaseApiInfo());
  102. }
  103. private ApiInfo jwBaseApiInfo() {
  104. ApiInfo apiInfo = new ApiInfo("基卫2.0API",
  105. "基卫2.0基础扩展API,提供基卫2.0基础扩展相关服务。",
  106. "1.0",
  107. "No terms of service",
  108. "wenfujian@jkzl.com",
  109. "The Apache License, Version 2.0",
  110. "http://www.apache.org/licenses/LICENSE-2.0.html"
  111. );
  112. return apiInfo;
  113. }
  114. }