springfox.documentation.builders.PathSelectors Java Examples

The following examples show how to use springfox.documentation.builders.PathSelectors. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Swagger2Config.java    From sophia_scaffolding with Apache License 2.0 6 votes vote down vote up
/**
 * 创建RestApi 并包扫描controller
 * @return
 */
@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            //分组名称
            // .groupName("2.X版本")
            .select()
            // // 对所有api进行监控
            // .apis(RequestHandlerSelectors.any())
            .apis(RequestHandlerSelectors.basePackage(basePackage))
            //不显示错误的接口地址
            .paths(PathSelectors.any())
            //错误路径不监控
            .paths(Predicates.not(PathSelectors.regex("/error.*")))
            // .build();
            .build()
            .securityContexts(Lists.newArrayList(securityContext())).securitySchemes(Lists.<SecurityScheme>newArrayList(apiKey()));

}
 
Example #2
Source File: SwaggerConfig.java    From swagger-more with Apache License 2.0 6 votes vote down vote up
@Bean
@Autowired
public Docket complete(ServletContext servletContext) {
    List<ResponseMessage> responseMessageList = newArrayList();
    return new Docket(SWAGGER_2)
            .pathProvider(new RelativePathProvider(servletContext) {
                @Override
                public String getApplicationBasePath() {
                    return "/dubbo";
                }
            })
            .apiInfo(apiInfo())
            .select()
            .apis(ExtendRequestHandlerSelectors.dubboApi())
            .paths(PathSelectors.any())
            .build()
            .groupName("dubbo")
            .produces(Sets.newHashSet("application/json", "text/plain"))
            .consumes(Collections.singleton("application/json"))
            .useDefaultResponseMessages(false)
            .globalResponseMessage(RequestMethod.GET, responseMessageList)
            .globalResponseMessage(RequestMethod.POST, responseMessageList);
}
 
Example #3
Source File: ProductCompositeServiceApplication.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 6 votes vote down vote up
/**
 * Will exposed on $HOST:$PORT/swagger-ui.html
 *
 * @return
 */
@Bean
public Docket apiDocumentation() {

	return new Docket(SWAGGER_2)
		.select()
		.apis(basePackage("se.magnus.microservices.composite.product"))
		.paths(PathSelectors.any())
		.build()
			.globalResponseMessage(POST, emptyList())
			.globalResponseMessage(GET, emptyList())
			.globalResponseMessage(DELETE, emptyList())
			.apiInfo(new ApiInfo(
                   apiTitle,
                   apiDescription,
                   apiVersion,
                   apiTermsOfServiceUrl,
                   new Contact(apiContactName, apiContactUrl, apiContactEmail),
                   apiLicense,
                   apiLicenseUrl,
                   emptyList()
               ));
   }
 
Example #4
Source File: Swagger2Config.java    From spring-cloud-learning with MIT License 6 votes vote down vote up
@Bean
public Docket createRestApi() {

    ParameterBuilder tokenPar = new ParameterBuilder();
    List<Parameter> pars = new ArrayList<Parameter>();
    tokenPar.name("x-access-token").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
    pars.add(tokenPar.build());

    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.qianlq.core.controller"))
            .paths(PathSelectors.any())
            .build()
            .globalOperationParameters(pars);
}
 
Example #5
Source File: TppSwaggerConfig.java    From XS2A-Sandbox with Apache License 2.0 6 votes vote down vote up
@Bean
public Docket apiDocklet() {
    return new Docket(DocumentationType.SWAGGER_2)
               .apiInfo(new ApiInfoBuilder()
                            .title("TPP backend application")
                            .description("TPP backend application of PSD2 Sandbox Environment")
                            .contact(new Contact(
                                "Adorsys GmbH & Co. KG",
                                "https://adorsys.de",
                                "[email protected]")
                            )
                            .version(buildProperties.getVersion() + " " + buildProperties.get("build.number"))
                            .build())
               .groupName("TPP-API")
               .select()
               .apis(RequestHandlerSelectors
                         .basePackage("de.adorsys.psd2.sandbox.tpp.rest"))
               .paths(PathSelectors.any())
               .build()
               .securitySchemes(singletonList(securitySchema()));
}
 
Example #6
Source File: CertificateSwaggerConfig.java    From XS2A-Sandbox with Apache License 2.0 6 votes vote down vote up
@Bean
public Docket apiDocket() {
    return new Docket(DocumentationType.SWAGGER_2)
               .apiInfo(new ApiInfoBuilder()
                            .title("Certificate Generator")
                            .description("Certificate Generator for Testing Purposes of PSD2 Sandbox Environment")
                            .contact(new Contact(
                                "adorsys GmbH & Co. KG",
                                "https://adorsys.de",
                                "[email protected]"))
                            .version(buildProperties.getVersion() + " " + buildProperties.get("build.number"))
                            .build())
               .groupName("Certificate Generator API")
               .select()
               .apis(RequestHandlerSelectors.basePackage("de.adorsys.psd2.sandbox.certificate"))
               .paths(PathSelectors.any())
               .build();
}
 
Example #7
Source File: Swagger2Config.java    From spring-boot-plus with Apache License 2.0 6 votes vote down vote up
@Bean
public Docket createRestApi() {
    // 获取需要扫描的包
    String[] basePackages = getBasePackages();
    ApiSelectorBuilder apiSelectorBuilder = new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select();
    // 如果扫描的包为空,则默认扫描类上有@Api注解的类
    if (ArrayUtils.isEmpty(basePackages)) {
        apiSelectorBuilder.apis(RequestHandlerSelectors.withClassAnnotation(Api.class));
    } else {
        // 扫描指定的包
        apiSelectorBuilder.apis(basePackage(basePackages));
    }
    Docket docket = apiSelectorBuilder.paths(PathSelectors.any())
            .build()
            .enable(swaggerProperties.isEnable())
            .ignoredParameterTypes(ignoredParameterTypes)
            .globalOperationParameters(getParameters());
    return docket;
}
 
Example #8
Source File: SwaggerConfig.java    From java-pay with Apache License 2.0 6 votes vote down vote up
@Bean
public Docket weiXinApi() {
    Parameter parameter = new ParameterBuilder()
            .name("Authorization")
            .description("token")
            .modelRef(new ModelRef("string"))
            .parameterType("header")
            .required(false)
            .defaultValue("token ")
            .build();

    return new Docket(DocumentationType.SWAGGER_2)
            .groupName("微信API接口文档")
            .globalOperationParameters(Collections.singletonList(parameter))
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.andy.pay.wx"))
            .paths(PathSelectors.any())
            .build();
}
 
Example #9
Source File: ProductCompositeServiceApplication.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 6 votes vote down vote up
/**
 * Will exposed on $HOST:$PORT/swagger-ui.html
 *
 * @return
 */
@Bean
public Docket apiDocumentation() {

	return new Docket(SWAGGER_2)
		.select()
		.apis(basePackage("se.magnus.microservices.composite.product"))
		.paths(PathSelectors.any())
		.build()
			.globalResponseMessage(POST, emptyList())
			.globalResponseMessage(GET, emptyList())
			.globalResponseMessage(DELETE, emptyList())
			.apiInfo(new ApiInfo(
                   apiTitle,
                   apiDescription,
                   apiVersion,
                   apiTermsOfServiceUrl,
                   new Contact(apiContactName, apiContactUrl, apiContactEmail),
                   apiLicense,
                   apiLicenseUrl,
                   emptyList()
               ));
   }
 
Example #10
Source File: ProductCompositeServiceApplication.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 6 votes vote down vote up
/**
 * Will exposed on $HOST:$PORT/swagger-ui.html
 *
 * @return
 */
@Bean
public Docket apiDocumentation() {

	return new Docket(SWAGGER_2)
		.select()
		.apis(basePackage("se.magnus.microservices.composite.product"))
		.paths(PathSelectors.any())
		.build()
			.globalResponseMessage(POST, emptyList())
			.globalResponseMessage(GET, emptyList())
			.globalResponseMessage(DELETE, emptyList())
			.apiInfo(new ApiInfo(
                   apiTitle,
                   apiDescription,
                   apiVersion,
                   apiTermsOfServiceUrl,
                   new Contact(apiContactName, apiContactUrl, apiContactEmail),
                   apiLicense,
                   apiLicenseUrl,
                   emptyList()
               ));
   }
 
Example #11
Source File: SwaggerConfig.java    From mPaaS with Apache License 2.0 6 votes vote down vote up
/**
 * 动态产生Docket分组信息
 *
 * @return
 */
@Autowired
public void dynamicConfiguration() {
    ConfigurableApplicationContext context = (ConfigurableApplicationContext) applicationContext;
    DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) context.getBeanFactory();

    String systemName = "Microservice PaaS";
    ApiInfoBuilder apiInfoBuilder = new ApiInfoBuilder()
            .description("mPaas前端后端对应接口")
            .version("1.0.1")
            .license("Code Farmer Framework(iByte) Org.");

    Map<String, ModuleMappingInfo> moduleInfo = mappingHelper.getMappingInfos();
    for (Map.Entry<String, ModuleMappingInfo> entry : moduleInfo.entrySet()) {
        beanFactory.registerSingleton(entry.getKey(), new Docket(DocumentationType.SWAGGER_2)
                .groupName(entry.getKey())
                .apiInfo(apiInfoBuilder.title(systemName + NamingConstant.DOT + entry.getKey()).build())
                .select()
                .apis(genSubPackage(entry.getKey()))
                .paths(Predicates.or(PathSelectors.ant(NamingConstant.PATH_PREFIX_DATA + "/**"),
                        PathSelectors.ant(NamingConstant.PATH_PREFIX_API + "/**")))
                .build());
    }
}
 
Example #12
Source File: Swagger2Config.java    From sophia_scaffolding with Apache License 2.0 6 votes vote down vote up
/**
 * 创建RestApi 并包扫描controller
 * @return
 */
@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            //分组名称
            // .groupName("2.X版本")
            .select()
            // // 对所有api进行监控
            // .apis(RequestHandlerSelectors.any())
            .apis(RequestHandlerSelectors.basePackage(basePackage))
            //不显示错误的接口地址
            .paths(PathSelectors.any())
            //错误路径不监控
            .paths(Predicates.not(PathSelectors.regex("/error.*")))
            // .build();
            .build()
            .securityContexts(Lists.newArrayList(securityContext())).securitySchemes(Lists.<SecurityScheme>newArrayList(apiKey()));

}
 
Example #13
Source File: Swagger2Config.java    From SpringBoot-Home with Apache License 2.0 5 votes vote down vote up
@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            // 指定controller存放的目录路径
            .apis(RequestHandlerSelectors.basePackage("cn.van.easyexcel.export.web.controller"))
            .paths(PathSelectors.any())
            .build();
}
 
Example #14
Source File: SwaggerConfig.java    From match-trade with Apache License 2.0 5 votes vote down vote up
@Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(CONTROLLER_URL))
                .paths(PathSelectors.any())
                .build();
//				.globalOperationParameters( new ArrayList<Parameter>(){{
//					//token参数
//					add(new ParameterBuilder(){{
//						name("token").description("登录token-需要登录的接口必须传递").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
//					}}.build());
//				}})
    }
 
Example #15
Source File: Swagger2.java    From mogu_blog_v2 with Apache License 2.0 5 votes vote down vote up
@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
            .paths(PathSelectors.any())
            .build();

}
 
Example #16
Source File: Swagger2Config.java    From macrozheng with Apache License 2.0 5 votes vote down vote up
@Bean
public Docket createRestApi(){
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.macro.mall.controller"))
            .paths(PathSelectors.any())
            .build()
            .securitySchemes(securitySchemes())
            .securityContexts(securityContexts());
}
 
Example #17
Source File: Swagger2.java    From mogu_blog_v2 with Apache License 2.0 5 votes vote down vote up
@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2).
            useDefaultResponseMessages(false)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
            .paths(PathSelectors.regex("^(?!auth).*$"))
            .build()
            .securitySchemes(securitySchemes())
            .securityContexts(securityContexts())
            ;
}
 
Example #18
Source File: SwaggerConfiguration.java    From Spring-5.0-By-Example with MIT License 5 votes vote down vote up
@Bean
public Docket documentation() {
  return new Docket(DocumentationType.SWAGGER_2)
      .select()
      .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
      .paths(PathSelectors.any())
      .build();
}
 
Example #19
Source File: Swagger2Config.java    From mall-learning with Apache License 2.0 5 votes vote down vote up
@Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //为当前包下controller生成API文档
                .apis(RequestHandlerSelectors.basePackage("com.macro.mall.tiny.controller"))
                //为有@Api注解的Controller生成API文档
//                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                //为有@ApiOperation注解的方法生成API文档
//                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
    }
 
Example #20
Source File: SwaggerConfig.java    From BlogManagePlatform with Apache License 2.0 5 votes vote down vote up
/**
 * 配置访问路径
 * @author Frodez
 * @date 2019-01-06
 */
private List<SecurityContext> securityContext() {
	// 注意要与RestfulAPI路径一致
	SecurityContextBuilder builder = SecurityContext.builder();
	builder.securityReferences(defaultAuth());
	builder.forPaths(PathSelectors.regex(PropertyUtil.get(PropertyKey.Web.BASE_PATH)));
	return List.of(builder.build());
}
 
Example #21
Source File: Swagger2.java    From Redis-4.x-Cookbook with MIT License 5 votes vote down vote up
@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("packt.rediscookbook"))
            .paths(PathSelectors.any())
            .build();
}
 
Example #22
Source File: SwaggerConfig.java    From cloud-service with MIT License 5 votes vote down vote up
@Bean
public Docket docket() {
	return new Docket(DocumentationType.SWAGGER_2).groupName("日志中心swagger接口文档")
			.apiInfo(new ApiInfoBuilder().title("日志中心swagger接口文档")
					.contact(new Contact("allen", "", "[email protected]")).version("1.0").build())
			.select().paths(PathSelectors.any()).build();
}
 
Example #23
Source File: SwaggerConfig.java    From coditori with Apache License 2.0 5 votes vote down vote up
@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.any())
            .paths(PathSelectors.any())
            .build();
}
 
Example #24
Source File: SwaggerConfig.java    From cloud-service with MIT License 5 votes vote down vote up
@Bean
public Docket docket() {
	return new Docket(DocumentationType.SWAGGER_2).groupName("管理后台swagger接口文档")
			.apiInfo(new ApiInfoBuilder().title("管理后台swagger接口文档")
					.contact(new Contact("allen", "", "[email protected]")).version("1.0").build())
			.select().paths(PathSelectors.any()).build();
}
 
Example #25
Source File: SwaggerConfig.java    From blockchain with Apache License 2.0 5 votes vote down vote up
@Bean
public Docket api() {
	return new Docket(DocumentationType.SWAGGER_2)
			.apiInfo(apiInfo())
			.select()
			.apis(RequestHandlerSelectors.basePackage("org.rockyang.blockchain.web.controller.api"))
			.paths(PathSelectors.any())
			.build();
}
 
Example #26
Source File: SwaggerConfiguration.java    From ola with Apache License 2.0 5 votes vote down vote up
@Bean
public Docket newsApi() {
    return new Docket(DocumentationType.SWAGGER_2)
        .apiInfo(apiInfo())
        .select()
        .paths(PathSelectors.any())
        .build()
        .pathMapping("/");
}
 
Example #27
Source File: SwaggerConfiguration.java    From spring-boot with Apache License 2.0 5 votes vote down vote up
@Bean
@Primary
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage(properties.getApi()))
            .paths(PathSelectors.any())
            .build();
}
 
Example #28
Source File: SwaggerConfig.java    From JetfireCloud with Apache License 2.0 5 votes vote down vote up
@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.springboot.services.producer"))
            .paths(PathSelectors.any())
            .build();
}
 
Example #29
Source File: Swagger2Config.java    From SuperBoot with MIT License 5 votes vote down vote up
@Bean
public Docket createRestApi() {// 创建API基本信息
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            //添加全局属性
            .globalOperationParameters(addGlobalOperationParameters())
            .select()
            // 扫描该包下的所有需要在Swagger中展示的API,@ApiIgnore注解标注的除外
            .apis(RequestHandlerSelectors.basePackage(BaseConstants.CONTROLLER_BASE_PATH))
            .paths(PathSelectors.any())
            .build();
}
 
Example #30
Source File: SwaggerConfig.java    From WIFIProbe with Apache License 2.0 5 votes vote down vote up
@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.codingfairy.web.controller"))
            .paths(PathSelectors.any())
            .build();
}