SwaggerConfig.java 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package com.yihu.figure.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 org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
  6. import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
  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. /**
  14. * Created by chenweida on 2016/2/3.
  15. */
  16. @Configuration
  17. @EnableSwagger2
  18. public class SwaggerConfig extends WebMvcConfigurerAdapter {
  19. private static final String PUBLIC_API = "Default";
  20. @Override
  21. public void addResourceHandlers(ResourceHandlerRegistry registry) {
  22. registry.addResourceHandler("swagger-ui.html")
  23. .addResourceLocations("classpath:/META-INF/resources/");
  24. registry.addResourceHandler("/webjars/**")
  25. .addResourceLocations("classpath:/META-INF/resources/webjars/");
  26. }
  27. @Bean
  28. public Docket publicAPI() {
  29. return new Docket(DocumentationType.SWAGGER_2)
  30. .groupName(PUBLIC_API)
  31. .genericModelSubstitutes(DeferredResult.class)
  32. .useDefaultResponseMessages(false)
  33. .forCodeGeneration(true)
  34. .pathMapping("/")
  35. .select()
  36. .paths(or(
  37. regex("/medicinal/.*"),
  38. regex("/diet/.*"),
  39. regex("/disease/.*"),
  40. regex("/data/.*"),
  41. regex("/health/.*")
  42. ))
  43. .build()
  44. .apiInfo(publicApiInfo());
  45. }
  46. private ApiInfo publicApiInfo() {
  47. ApiInfo apiInfo = new ApiInfo("居民画像API",
  48. "居民画像接口。",
  49. "1.0",
  50. "No terms of service",
  51. "admin@jkzl.com",
  52. "The Apache License, Version 2.0",
  53. "http://www.apache.org/licenses/LICENSE-2.0.html"
  54. );
  55. return apiInfo;
  56. }
  57. }