org.springframework.boot.autoconfigure.SpringBootApplication#springfox.documentation.builders.RequestHandlerSelectors源码实例Demo

下面列出了org.springframework.boot.autoconfigure.SpringBootApplication#springfox.documentation.builders.RequestHandlerSelectors 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: mica   文件: SwaggerConfiguration.java
@Bean
public Docket createRestApi(ApplicationContext context,
							MicaSwaggerProperties properties) {
	// 组名为应用名
	String appName = context.getId();
	Docket docket = new Docket(DocumentationType.SWAGGER_2)
		.useDefaultResponseMessages(false)
		.globalOperationParameters(globalHeaders(properties))
		.apiInfo(apiInfo(appName, properties)).select()
		.apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
		.paths(PathSelectors.any())
		.build();
	// 如果开启认证
	if (properties.getAuthorization().getEnabled()) {
		docket.securitySchemes(Collections.singletonList(apiKey(properties)));
		docket.securityContexts(Collections.singletonList(securityContext(properties)));
	}
	return docket;
}
 
源代码2 项目: yshopmall   文件: SwaggerConfig.java
@Bean
@SuppressWarnings("all")
public Docket createRestApi() {
    ParameterBuilder ticketPar = new ParameterBuilder();
    List<Parameter> pars = new ArrayList<>();
    ticketPar.name(tokenHeader).description("token")
            .modelRef(new ModelRef("string"))
            .parameterType("header")
            .defaultValue(tokenStartWith + " ")
            .required(true)
            .build();
    pars.add(ticketPar.build());
    return new Docket(DocumentationType.SWAGGER_2)
            .enable(enabled)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("co.yixiang.modules"))
            .paths(Predicates.not(PathSelectors.regex("/error.*")))
            .build()
            .globalOperationParameters(pars);
}
 
源代码3 项目: oncokb   文件: MvcConfigurationPublic.java
@Bean
public Docket publicApi() {
    String swaggerDescription = PropertiesUtils.getProperties(SWAGGER_DESCRIPTION);
    String finalDescription = StringUtils.isNullOrEmpty(swaggerDescription) ? SWAGGER_DEFAULT_DESCRIPTION : swaggerDescription;
    return new Docket(DocumentationType.SWAGGER_2)
        .groupName("Public APIs")
        .select()
        .apis(RequestHandlerSelectors.withMethodAnnotation(PublicApi.class))
        .build()
        .apiInfo(new ApiInfo(
            "OncoKB APIs",
            finalDescription,
            PUBLIC_API_VERSION,
            "https://www.oncokb.org/terms",
            new Contact("OncoKB", "https://www.oncokb.org", "[email protected]"),
            "Terms of Use",
            "https://www.oncokb.org/terms"
        ))
        .useDefaultResponseMessages(false);
}
 
源代码4 项目: DimpleBlog   文件: SwaggerConfig.java
/**
 * 创建API
 */
@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .enable(enabled)
            // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息)
            .apiInfo(apiInfo())
            // 设置哪些接口暴露给Swagger展示
            .select()
            // 扫描所有有注解的api,用这种方式更灵活
            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
            // 扫描指定包中的swagger注解
            //.apis(RequestHandlerSelectors.basePackage("com.dimple.project.tool.swagger"))
            // 扫描所有 .apis(RequestHandlerSelectors.any())
            .paths(PathSelectors.any())
            .build()
            /* 设置安全模式,swagger可以设置访问token */
            .securitySchemes(securitySchemes())
            .securityContexts(securityContexts())
            .pathMapping(pathMapping);
}
 
源代码5 项目: XS2A-Sandbox   文件: CertificateSwaggerConfig.java
@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();
}
 
源代码6 项目: java-pay   文件: SwaggerConfig.java
@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();
}
 
private Predicate<RequestHandler> getControllerPredicate() {
    groupName = groupList.get(groupIndex);
    List<String> apiTags = groupMap.get(groupName);
    Predicate<RequestHandler> methodPredicate = (input) -> {
        Api api = null;
        Optional<Api> apiOptional = input.findControllerAnnotation(Api.class);
        if (apiOptional.isPresent()) {
            api = apiOptional.get();
        }
        List<String> tags = Arrays.asList(api.tags());
        if (api != null && apiTags.containsAll(tags)) {
            return true;
        }
        return false;
    };
    groupIndex++;
    return Predicates.and(RequestHandlerSelectors.withClassAnnotation(RestController.class), methodPredicate);
}
 
源代码8 项目: api-layer   文件: SwaggerConfiguration.java
@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
        .select()
        .apis(RequestHandlerSelectors.basePackage("org.zowe.apiml.apicatalog.controllers.api"))
        .paths(
            PathSelectors.any()
        )
        .build()
        .securitySchemes(
            Arrays.asList(
                new BasicAuth("LoginBasicAuth"),
                new ApiKey("CookieAuth", "apimlAuthenticationToken", "header")
            )
        )
        .apiInfo(
            new ApiInfo(
                apiTitle,
                apiDescription,
                apiVersion,
                null,
                null,
                null,
                null,
                Collections.emptyList()
            )
        );
}
 
源代码9 项目: open-capacity-platform   文件: SwaggerConfig.java
@Bean
	public Docket createRestApi() {
		ParameterBuilder tokenPar = new ParameterBuilder();
		List<Parameter> pars = new ArrayList<>();
		tokenPar.name("Authorization").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.open.capacity"))
				.apis(RequestHandlerSelectors.any())
//				.paths( input ->PathSelectors.regex("/user.*").apply(input) || PathSelectors.regex("/permissions.*").apply(input) 
//						|| PathSelectors.regex("/roles.*").apply(input) || PathSelectors.regex("/test.*").apply(input)
//				)
				 .paths(PathSelectors.any())
				.build().globalOperationParameters(pars);
	}
 
源代码10 项目: open-capacity-platform   文件: SwaggerConfig.java
@Bean
public Docket createRestApi() {
	
	
	ParameterBuilder tokenPar = new ParameterBuilder();
	List<Parameter> pars = new ArrayList<>();
	tokenPar.name("Authorization").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.open.capacity"))
			.apis(RequestHandlerSelectors.any())
		    .paths(PathSelectors.any())
			.build().globalOperationParameters(pars);
}
 
源代码11 项目: spring-boot-plus   文件: Swagger2Config.java
@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;
}
 
源代码12 项目: pig   文件: SwaggerConfig.java
@Bean
public Docket createRestApi() {
    ParameterBuilder tokenBuilder = new ParameterBuilder();
    List<Parameter> parameterList = new ArrayList<>();
    tokenBuilder.name("Authorization")
            .defaultValue("去其他请求中获取heard中token参数")
            .description("令牌")
            .modelRef(new ModelRef("string"))
            .parameterType("header")
            .required(true).build();
    parameterList.add(tokenBuilder.build());
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
            .paths(PathSelectors.any())
            .build()
            .globalOperationParameters(parameterList);
}
 
源代码13 项目: AuTe-Framework   文件: MockApplication.java
@Bean
public Docket wiremockApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.any())
            .paths(PathSelectors.regex(".*__admin.*"))
            .build()
            .pathMapping("/")
            .directModelSubstitute(LocalDate.class,
                    String.class)
            .alternateTypeRules(
                    newRule(typeResolver.resolve(DeferredResult.class,
                            typeResolver.resolve(ResponseEntity.class, WildcardType.class)),
                            typeResolver.resolve(WildcardType.class)))
            .useDefaultResponseMessages(false)
            .globalResponseMessage(RequestMethod.GET,
                    newArrayList(new ResponseMessageBuilder()
                            .code(500)
                            .message("Http error 500")
                            .build()))
            .enableUrlTemplating(true);
}
 
源代码14 项目: spring-cloud-learning   文件: Swagger2Config.java
@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);
}
 
源代码15 项目: common-mvc   文件: SwaggerConfig.java
@Bean
public Docket createRestApi() {
    //统一增加权限验证字段
    List<Parameter> params = new ArrayList<Parameter>();
    ParameterBuilder tokenParam = new ParameterBuilder();
    tokenParam.name("Authorization").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(true).build();
    params.add(tokenParam.build());

    return new Docket(DocumentationType.SWAGGER_2)
            .enable(enabled)
            .apiInfo(apiInfo()).select()
                    //扫描指定包中的swagger注解
                    //.apis(RequestHandlerSelectors.basePackage("com.github.misterchangray.controller"))
                    //扫描所有有注解的api,用这种方式更灵活
            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
            .paths(PathSelectors.any())
            .build().globalOperationParameters(params);
}
 
源代码16 项目: spring-cloud-demo   文件: SwaggerConfig.java
@Bean
public Docket api() {
    log.info("start init swagger2");
    /**
     * 为所有swagger UI 上面的请求默认添加一个 authorization 参数,方便测试
     * **/
    Parameter param = new ParameterBuilder()
        .parameterType("header")
        .name("Authorization")
        .description("Used for oauth authentication")
        .modelRef(new ModelRef("string"))
        .required(false)
        .build();
    List<Parameter> params = new ArrayList<>();
    params.add(param);
    return new Docket(DocumentationType.SWAGGER_2)
        .select()
        .apis(RequestHandlerSelectors.basePackage("com.yong.orders.controller"))
        .paths(regex(".*"))
        .build()
        .globalOperationParameters(params);
}
 
源代码17 项目: onetwo   文件: ScanPluginAsGroupSwaggerConfig.java
final protected Collection<Predicate<RequestHandler>> createPackagePredicateByClass(Class<?>... rootClass) {
	return Stream.of(rootClass)
				.map(c -> {
					return RequestHandlerSelectors.basePackage(ClassUtils.getPackageName(c));
				})
				.collect(Collectors.toSet());
}
 
源代码18 项目: teaching   文件: Swagger2Config.java
/**
 * swagger2的配置文件,这里可以配置swagger2的一些基本的内容,比如扫描的包等等
 *
 * @return Docket
 */
@Bean
public Docket createRestApi() {
	return new Docket(DocumentationType.SWAGGER_2)
			.apiInfo(apiInfo())
			.select()
			//此包路径下的类,才生成接口文档
			.apis(RequestHandlerSelectors.basePackage("org.jeecg.modules"))
			//加了ApiOperation注解的类,才生成接口文档
            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
			.paths(PathSelectors.any())
			.build()
			.securitySchemes(Collections.singletonList(securityScheme()));
			//.globalOperationParameters(setHeaderToken());
}
 
源代码19 项目: Raincat   文件: SwaggerConfig.java
@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
            .build().pathMapping("/").directModelSubstitute(LocalDate.class, String.class)
            .genericModelSubstitutes(ResponseEntity.class).useDefaultResponseMessages(false)
            .globalResponseMessage(RequestMethod.GET, newArrayList(new ResponseMessageBuilder().code(500).message("500 message")
                    .responseModel(new ModelRef("Error")).build()));
}
 
源代码20 项目: alcor   文件: SwaggerConfig.java
@Bean
public Docket api(){
    return new Docket(DocumentationType.SWAGGER_2)
        .apiInfo(apiInfo())
        .select()
        .apis(RequestHandlerSelectors.any())
        .paths(PathSelectors.regex("(?!/error).+"))
        .paths(PathSelectors.regex("(?!/actuator).+"))
        .build();
}
 
@Bean
public Docket swaggerSpringfoxDocket() {
    log.debug("Starting Swagger");
    StopWatch watch = new StopWatch();
    watch.start();
    Docket docket = new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any()).paths(PathSelectors.any()).build().pathMapping("/")
            .genericModelSubstitutes(ResponseEntity.class);
    watch.stop();
    log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis());
    return docket;
}
 
源代码22 项目: HIS   文件: Swagger2Config.java
@Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.neu.his.cloud.service.pms.controller"))
                .paths(PathSelectors.any())
                .build();
//                .securitySchemes(securitySchemes())
//                .securityContexts(securityContexts());
    }
 
源代码23 项目: wx-crawl   文件: Swagger2.java
@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.xuzp.controller"))
            .paths(PathSelectors.any())
            .build();
}
 
@Bean
public Docket api() {
	return new Docket(DocumentationType.SWAGGER_2)
			.select()
			.apis(RequestHandlerSelectors.any())
			.paths(PathSelectors.any())
			.build()
			.apiInfo(apiInfo());
}
 
源代码25 项目: DiscordSoundboard   文件: SwaggerConfig.java
/****
 * Swagger Configuration.
 */
@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.any())
            .paths(PathSelectors.any())
            .build();
}
 
@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo()).select()
            .apis(RequestHandlerSelectors.basePackage("com.dockerx.rxjavaweb")).paths(
                    PathSelectors.any()).build();
}
 
源代码27 项目: DBus   文件: SwaggerConfig.java
@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_BASE_PACKAGE))
            .build()
            //.directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class)
            //.directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class)
            .apiInfo(apiInfo());
}
 
源代码28 项目: EasyReport   文件: SwaggerConfig.java
@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
        .apiInfo(this.apiInfo())
        .select()
        .apis(RequestHandlerSelectors.basePackage("com.easytoolsoft.easyreport.web.controller"))
        .paths(PathSelectors.any())
        .build();
}
 
源代码29 项目: restful-booker-platform   文件: SwaggerConfig.java
@Bean
public Docket postsApi() {
    return new Docket(DocumentationType.SWAGGER_2).groupName("public-api")
            .apiInfo(apiInfo())
            .select()
                .apis(RequestHandlerSelectors.basePackage("com.automationintesting.api"))
                .paths(PathSelectors.any())
            .build();
}
 
源代码30 项目: myth   文件: SwaggerConfig.java
/**
 * Api docket.
 *
 * @return the docket
 */
@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
            // .paths(paths())
            .build().pathMapping("/").directModelSubstitute(LocalDate.class, String.class)
            .genericModelSubstitutes(ResponseEntity.class).useDefaultResponseMessages(false)
            .globalResponseMessage(RequestMethod.GET, newArrayList(new ResponseMessageBuilder().code(500).message("500 message")
                    .responseModel(new ModelRef("Error")).build()));
}