SwaggerConfig.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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.WechatContants;
  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.api_common+"/.*")
  33. ,regex("/"+ WechatContants.api_common+"/.*")
  34. ,regex("/"+ WechatContants.WxAccessToken.api_common+"/.*")
  35. ))
  36. .build()
  37. .apiInfo(publicApiInfo());
  38. }
  39. private ApiInfo publicApiInfo() {
  40. ApiInfo apiInfo = new ApiInfo("基卫2.0API",
  41. "基卫2.0API,提供基础卫生相关服务。",
  42. "1.0",
  43. "No terms of service",
  44. "wenfujian@jkzl.com",
  45. "The Apache License, Version 2.0",
  46. "http://www.apache.org/licenses/LICENSE-2.0.html"
  47. );
  48. return apiInfo;
  49. }
  50. @Bean
  51. public Docket wlyyAPI() {
  52. return new Docket(DocumentationType.SWAGGER_2)
  53. .groupName(Wlyy_API)
  54. .useDefaultResponseMessages(false)
  55. .forCodeGeneration(false)
  56. .pathMapping("/")
  57. .select()
  58. .paths(or(
  59. regex("/" + WlyyAgreementContants.Agreement.api_common + "/.*")
  60. , regex("/" + WlyyAgreementContants.AgreementKpi.api_common + "/.*")
  61. , regex("/" + WlyyAgreementContants.AgreementKpiLog.api_common + "/.*")
  62. , regex("/" + WlyyAgreementContants.SignFamily.api_common + "/.*")
  63. , regex("/" + WlyyPatientContants.Advertisement.api_common + "/.*")
  64. ))
  65. .build()
  66. .apiInfo(wlyyApiInfo());
  67. }
  68. private ApiInfo wlyyApiInfo() {
  69. ApiInfo wlyyInfo = new ApiInfo("基卫2.0API",
  70. "基卫2.0API,提供基础卫生相关服务。",
  71. "1.0",
  72. "No terms of service",
  73. "wenfujian@jkzl.com",
  74. "The Apache License, Version 2.0",
  75. "http://www.apache.org/licenses/LICENSE-2.0.html"
  76. );
  77. return wlyyInfo;
  78. }
  79. @Bean
  80. public Docket jwBaseAPI() {
  81. return new Docket(DocumentationType.SWAGGER_2)
  82. .groupName(Base_API)
  83. .useDefaultResponseMessages(false)
  84. .forCodeGeneration(false)
  85. .pathMapping("/")
  86. .select()
  87. .paths(or(
  88. regex("/"+ BaseContants.api_common+"/.*")
  89. ,regex("/"+ BaseContants.Saas.api_common+"/.*")
  90. ,regex("/"+ WechatContants.api_common+"/.*")
  91. ,regex("/"+ WechatContants.WxAccessToken.api_common+"/.*")
  92. ))
  93. .build()
  94. .apiInfo(jwBaseApiInfo());
  95. }
  96. private ApiInfo jwBaseApiInfo() {
  97. ApiInfo apiInfo = new ApiInfo("基卫2.0API",
  98. "基卫2.0基础扩展API,提供基卫2.0基础扩展相关服务。",
  99. "1.0",
  100. "No terms of service",
  101. "wenfujian@jkzl.com",
  102. "The Apache License, Version 2.0",
  103. "http://www.apache.org/licenses/LICENSE-2.0.html"
  104. );
  105. return apiInfo;
  106. }
  107. }