SwaggerConfig.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package com.yihu.jw.config;
  2. import com.yihu.jw.restmodel.base.BaseContants;
  3. import com.yihu.jw.restmodel.wlyy.WlyyContants;
  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("/" + WlyyContants.Agreement.api_common + "/.*")
  62. ,regex("/"+WlyyContants.AgreementKpi.api_common+"/.*")
  63. ,regex("/"+WlyyContants.AgreementKpiLog.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.Function.api_common+"/.*")
  89. ,regex("/"+ BaseContants.Saas.api_common+"/.*")
  90. ,regex("/"+ BaseContants.Module.api_common+"/.*")
  91. ))
  92. .build()
  93. .apiInfo(jwBaseApiInfo());
  94. }
  95. private ApiInfo jwBaseApiInfo() {
  96. ApiInfo apiInfo = new ApiInfo("基卫2.0API",
  97. "基卫2.0基础扩展API,提供基卫2.0基础扩展相关服务。",
  98. "1.0",
  99. "No terms of service",
  100. "wenfujian@jkzl.com",
  101. "The Apache License, Version 2.0",
  102. "http://www.apache.org/licenses/LICENSE-2.0.html"
  103. );
  104. return apiInfo;
  105. }
  106. }