springfox.documentation.builders.RequestHandlerSelectors Java Examples

The following examples show how to use springfox.documentation.builders.RequestHandlerSelectors. 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: SwaggerConfiguration.java    From api-layer with Eclipse Public License 2.0 7 votes vote down vote up
@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()
            )
        );
}
 
Example #2
Source File: SwaggerConfig.java    From pig with MIT License 6 votes vote down vote up
@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);
}
 
Example #3
Source File: SwaggerConfig.java    From yshopmall with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #4
Source File: MvcConfigurationPublic.java    From oncokb with GNU Affero General Public License v3.0 6 votes vote down vote up
@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);
}
 
Example #5
Source File: SwaggerConfig.java    From DimpleBlog with Apache License 2.0 6 votes vote down vote up
/**
 * 创建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);
}
 
Example #6
Source File: SwaggerConfiguration.java    From mica with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example #7
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 #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: SwaggerConfig.java    From spring-cloud-demo with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #10
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 #11
Source File: SmartSwaggerDynamicGroupConfig.java    From smart-admin with MIT License 6 votes vote down vote up
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);
}
 
Example #12
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 #13
Source File: MockApplication.java    From AuTe-Framework with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #14
Source File: SwaggerConfig.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #15
Source File: SwaggerConfig.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@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);
	}
 
Example #16
Source File: SwaggerConfig.java    From common-mvc with MIT License 6 votes vote down vote up
@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);
}
 
Example #17
Source File: Swagger2.java    From parker 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("com.wu.parker"))
            .paths(PathSelectors.any())
            .build();
}
 
Example #18
Source File: SwaggerConfig.java    From singleton with Eclipse Public License 2.0 5 votes vote down vote up
@Bean
public Docket createRestApi1() {
	if (authConfig.getAuthSwitch().equalsIgnoreCase("true")) {
		return new Docket(DocumentationType.SWAGGER_2).groupName(APIV1.V).apiInfo(apiInfo(APIV1.V)).select()
				.apis(RequestHandlerSelectors.basePackage("com.vmware.vip.i18n.api.v1")).paths(PathSelectors.any())
				.build().globalOperationParameters(createParameter());
	} else {
		return new Docket(DocumentationType.SWAGGER_2).groupName(APIV1.V).apiInfo(apiInfo(APIV1.V)).select()
				.apis(RequestHandlerSelectors.basePackage("com.vmware.vip.i18n.api.v1")).paths(PathSelectors.any())
				.build();
	}
}
 
Example #19
Source File: Swagger2Config.java    From xmall 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("com.yzsunlei.xmall.app.controller"))
            .paths(PathSelectors.any())
            .build();
}
 
Example #20
Source File: DocAutoConfiguration.java    From dew with Apache License 2.0 5 votes vote down vote up
/**
 * Rest api docket.
 *
 * @param servletContext the servlet context
 * @return the docket
 */
@Bean
public Docket restApi(ServletContext servletContext) {
    return new Docket(DocumentationType.SWAGGER_2)
            .tags(new Tag(FLAG_APPLICATION_NAME, Dew.Info.name))
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage(dewConfig.getBasic().getDoc().getBasePackage()))
            .paths(PathSelectors.any())
            .build()
            /*.securitySchemes(new ArrayList<ApiKey>() {{
                add(new ApiKey("access_token", "accessToken", "develop"));
            }})
            .globalOperationParameters(new ArrayList<Parameter>() {{
                add(new ParameterBuilder()
                        .name(Dew.dewConfig.getSecurity().getTokenFlag())
                        .description("token 用于鉴权,部分接口必须传入")
                        .modelRef(new ModelRef("String"))
                        .parameterType(Dew.dewConfig.getSecurity().isTokenInHeader() ? "header" : "query")
                        .hidden(false)
                        .required(true)
                        .build());
            }})*/
            .pathProvider(new RelativePathProvider(servletContext) {
                @Override
                public String getApplicationBasePath() {
                    return contextPath + super.getApplicationBasePath();
                }
            });
}
 
Example #21
Source File: SwaggerConfiguration.java    From cxf-spring-cloud-netflix-docker with MIT License 5 votes vote down vote up
@Bean
public Docket api() {
	return new Docket(DocumentationType.SWAGGER_2)
			.apiInfo(apiInfo())
			.select()
			.apis(RequestHandlerSelectors.any())
			.paths(PathSelectors.any())
			.build();
}
 
Example #22
Source File: SwaggerConfig.java    From java-tutorial with MIT License 5 votes vote down vote up
@Bean
public Docket createRestApi() {
    ApiInfo apiInfo = new ApiInfoBuilder()
            .title("Api Document")
            .description("springboot-samples api document")
            .version("1.0")
            .build();

    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo)
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.marvel.controller"))
            .paths(PathSelectors.any())
            .build();
}
 
Example #23
Source File: Swagger2Config.java    From SpringBootBucket with MIT License 5 votes vote down vote up
@Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .produces(Sets.newHashSet("application/json"))
                .consumes(Sets.newHashSet("application/json"))
                .protocols(Sets.newHashSet("http", "https"))
                .apiInfo(apiInfo())
                .forCodeGeneration(true)
                .select()
                // 指定controller存放的目录路径
                .apis(RequestHandlerSelectors.basePackage("com.xncoding.jwt.api"))
//                .paths(PathSelectors.ant("/api/v1/*"))
                .paths(PathSelectors.any())
                .build();
    }
 
Example #24
Source File: Swagger2.java    From Demo 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.nasus.controller"))
            .paths(PathSelectors.any())
            .build();
}
 
Example #25
Source File: SwaggerConfig.java    From Java-9-Spring-Webflux 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("com.dockerx.rxreact")).paths(
                    PathSelectors.any()).build();
}
 
Example #26
Source File: Swagger2.java    From parker 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("com.wu.parker"))
            .paths(PathSelectors.any())
            .build();
}
 
Example #27
Source File: Swagger2Config.java    From HIS 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.neu.his.cloud.service.bms.controller"))
                .paths(PathSelectors.any())
                .build();
//                .securitySchemes(securitySchemes())
//                .securityContexts(securityContexts());
    }
 
Example #28
Source File: Swagger2.java    From yes-cart with Apache License 2.0 5 votes vote down vote up
@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            //.apis(RequestHandlerSelectors.basePackage("org.yes.cart.service.endpoint.impl"))
            .apis(RequestHandlerSelectors.any())
            .paths(PathSelectors.regex("(?!/error).+"))
            .paths(PathSelectors.regex("(?!/connector).+"))
            .paths(PathSelectors.regex("^(?!.*\\.(jsp)($|\\?)).*"))
            .build()
            .securitySchemes(Arrays.asList(apiKey()))
            .apiInfo(apiInfo());
}
 
Example #29
Source File: FebsDocAutoConfigure.java    From FEBS-Cloud with Apache License 2.0 5 votes vote down vote up
@Bean
@Order(-1)
public Docket groupRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(groupApiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage(properties.getBasePackage()))
            .paths(PathSelectors.any())

            .build().securityContexts(Lists.newArrayList(securityContext())).securitySchemes(Lists.<SecurityScheme>newArrayList(apiKey()));
}
 
Example #30
Source File: SpringFoxConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
            .build();
}