123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package com.qxgmat.util.swagger;
- /**
- * Created by GaoJie on 2017/10/31.
- */
- import com.google.common.base.Predicate;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import springfox.documentation.builders.ApiInfoBuilder;
- import springfox.documentation.builders.RequestHandlerSelectors;
- import springfox.documentation.service.ApiInfo;
- import springfox.documentation.spi.DocumentationType;
- import springfox.documentation.spring.web.plugins.Docket;
- import springfox.documentation.swagger2.annotations.EnableSwagger2;
- import javax.servlet.ServletContext;
- import static com.google.common.base.Predicates.or;
- import static springfox.documentation.builders.PathSelectors.regex;
- @Configuration
- @EnableSwagger2
- public class SwaggerConfig {
- @Bean
- public Docket createFrontendApi(ServletContext servletContext) {
- return new Docket(DocumentationType.SWAGGER_2)
- .groupName("1.frontend")
- .apiInfo(apiFrontendInfo())
- .select()
- .apis(RequestHandlerSelectors.basePackage("com.qxgmat.controller"))
- .paths(webPath())
- .build()
- .useDefaultResponseMessages(false)
- .forCodeGeneration(true);
- }
- @Bean
- public Docket createBackendApi() {
- return new Docket(DocumentationType.SWAGGER_2)
- .groupName("2.backend")
- .apiInfo(apiBackendInfo())
- .select()
- .apis(RequestHandlerSelectors.basePackage("com.qxgmat.controller"))
- .paths(adminPath())
- .build()
- .useDefaultResponseMessages(false)
- .forCodeGeneration(true);
- }
- private Predicate<String> adminPath() {
- return or(
- regex("/admin.*"),
- regex("/common.*")
- );
- }
- private Predicate<String> webPath() {
- // return new Predicate<String>() {
- // @Override
- // public boolean apply(String input) {
- // return !input.contains("admin");
- // }
- // };
- return or(
- regex("/api.*"),
- regex("/common.*")
- );
- }
- private ApiInfo apiFrontendInfo() {
- return new ApiInfoBuilder()
- .title("前端API")
- .termsOfServiceUrl("")
- .version("1.0")
- .build();
- }
- private ApiInfo apiBackendInfo() {
- return new ApiInfoBuilder()
- .title("管理端API")
- .termsOfServiceUrl("")
- .version("1.0")
- .build();
- }
- }
|