SwaggerConfig.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package com.yihu.wlyy.config;
  2. import org.springframework.context.annotation.Bean;
  3. import org.springframework.context.annotation.Configuration;
  4. import org.springframework.web.context.request.async.DeferredResult;
  5. import springfox.documentation.builders.PathSelectors;
  6. import springfox.documentation.service.ApiInfo;
  7. import springfox.documentation.spi.DocumentationType;
  8. import springfox.documentation.spring.web.plugins.Docket;
  9. import springfox.documentation.swagger2.annotations.EnableSwagger2;
  10. import static com.google.common.base.Predicates.or;
  11. import static springfox.documentation.builders.PathSelectors.regex;
  12. @EnableSwagger2
  13. @Configuration
  14. public class SwaggerConfig {
  15. private static final String PUBLIC_API = "Default";
  16. private static final String Doctor_API = "doctor";
  17. private static final String Patient_API = "patient";
  18. private static final String Other_API = "other";
  19. @Bean
  20. public Docket publicAPI() {
  21. return new Docket(DocumentationType.SWAGGER_2)
  22. .groupName(Doctor_API)
  23. .genericModelSubstitutes(DeferredResult.class)
  24. .useDefaultResponseMessages(false)
  25. .forCodeGeneration(true)
  26. .pathMapping("/")
  27. .select()
  28. .paths(PathSelectors.regex("/doctor/.*"))
  29. .build()
  30. .apiInfo(publicApiInfo());
  31. }
  32. private ApiInfo publicApiInfo() {
  33. ApiInfo apiInfo = new ApiInfo("三师平台API",
  34. "向PC端,微信、App等应用提供功能与数据接口。",
  35. "1.0",
  36. "No terms of service",
  37. "admin@jkzl.com",
  38. "The Apache License, Version 2.0",
  39. "http://www.apache.org/licenses/LICENSE-2.0.html"
  40. );
  41. return apiInfo;
  42. }
  43. @Bean
  44. public Docket patientAPI() {
  45. return new Docket(DocumentationType.SWAGGER_2)
  46. .groupName(Patient_API)
  47. .genericModelSubstitutes(DeferredResult.class)
  48. .useDefaultResponseMessages(false)
  49. .forCodeGeneration(true)
  50. .pathMapping("/")
  51. .select()
  52. .paths(PathSelectors.regex("/patient/.*"))
  53. .build()
  54. .apiInfo(patientApiInfo());
  55. }
  56. private ApiInfo patientApiInfo() {
  57. ApiInfo apiInfo = new ApiInfo("三师平台API",
  58. "向PC端,微信、App等应用提供功能与数据接口。",
  59. "1.0",
  60. "No terms of service",
  61. "admin@jkzl.com",
  62. "The Apache License, Version 2.0",
  63. "http://www.apache.org/licenses/LICENSE-2.0.html"
  64. );
  65. return apiInfo;
  66. }
  67. @Bean
  68. public Docket otherAPI() {
  69. return new Docket(DocumentationType.SWAGGER_2)
  70. .groupName(Other_API)
  71. .genericModelSubstitutes(DeferredResult.class)
  72. .useDefaultResponseMessages(false)
  73. .forCodeGeneration(true)
  74. .pathMapping("/")
  75. .select()
  76. .paths(or(
  77. regex("/third/.*"),
  78. regex("/statistics/.*"),
  79. regex("/statistics/province/.*"),
  80. regex("/job/.*"),
  81. regex("/family_contract/.*"),
  82. regex("/hosptail/.*"),
  83. regex("/manage_util/.*"),
  84. regex("/common/.*"),
  85. regex("/hospitals/.*"),
  86. regex("/upload/.*"),
  87. regex("/weixin/.*"),
  88. regex("/wx/.*"),
  89. regex("/area/.*"),
  90. regex("/login/.*"),
  91. regex("/qrcode/.*"),
  92. regex("/onepay/.*"),
  93. regex("/wlyy_service/.*"),
  94. regex("/express/.*")
  95. ))
  96. .build()
  97. .apiInfo(otherApiInfo());
  98. }
  99. private ApiInfo otherApiInfo() {
  100. ApiInfo apiInfo = new ApiInfo("三师平台API",
  101. "向PC端,微信、App等应用提供功能与数据接口。",
  102. "1.0",
  103. "No terms of service",
  104. "admin@jkzl.com",
  105. "The Apache License, Version 2.0",
  106. "http://www.apache.org/licenses/LICENSE-2.0.html"
  107. );
  108. return apiInfo;
  109. }
  110. }