SwaggerConfig.java 3.2 KB

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