SwaggerConfig.java 4.4 KB

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