springfox.documentation.builders.ParameterBuilder Java Examples
The following examples show how to use
springfox.documentation.builders.ParameterBuilder.
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: Swagger2Configuration.java From flash-waimai with MIT License | 6 votes |
@Bean public Docket createRestApi() { //添加head参数start ParameterBuilder tokenPar = new ParameterBuilder(); List<Parameter> pars = new ArrayList<Parameter>(); tokenPar.name(Constants.TOKEN_NAME).description("Token").modelRef(new ModelRef("string")).parameterType("header").required(false).build(); pars.add(tokenPar.build()); //添加head参数end return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("cn.enilu.flash.api.controller")) .paths(PathSelectors.any()) .build().globalOperationParameters(pars); }
Example #2
Source File: SwaggerConfig.java From kitty with GNU Lesser General Public License v3.0 | 6 votes |
@Bean public Docket createRestApi(){ // 添加请求参数,我们这里把token作为请求头部参数传入后端 ParameterBuilder parameterBuilder = new ParameterBuilder(); List<Parameter> parameters = new ArrayList<Parameter>(); parameterBuilder.name("token").description("令牌") .modelRef(new ModelRef("string")).parameterType("header").required(false).build(); parameters.add(parameterBuilder.build()); return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select() .apis(RequestHandlerSelectors.any()).paths(PathSelectors.any()) .build().globalOperationParameters(parameters); // return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()) // .select() // .apis(RequestHandlerSelectors.any()) // .paths(PathSelectors.any()).build(); }
Example #3
Source File: Swagger2Config.java From spring-boot-plus with Apache License 2.0 | 6 votes |
/** * 添加额外参数 * * @return */ private List<Parameter> getParameters() { // 获取自定义参数配置 List<SwaggerProperties.ParameterConfig> parameterConfig = swaggerProperties.getParameterConfig(); if (CollectionUtils.isEmpty(parameterConfig)) { return null; } List<Parameter> parameters = new ArrayList<>(); parameterConfig.forEach(parameter -> { // 设置自定义参数 parameters.add(new ParameterBuilder() .name(parameter.getName()) .description(parameter.getDescription()) .modelRef(new ModelRef(parameter.getDataType())) .parameterType(parameter.getType()) .required(parameter.isRequired()) .defaultValue(parameter.getDefaultValue()) .build()); }); return parameters; }
Example #4
Source File: SwaggerAutoConfiguration.java From microservices-platform with Apache License 2.0 | 6 votes |
private List<Parameter> buildGlobalOperationParametersFromSwaggerProperties( List<SwaggerProperties.GlobalOperationParameter> globalOperationParameters) { List<Parameter> parameters = Lists.newArrayList(); if (Objects.isNull(globalOperationParameters)) { return parameters; } for (SwaggerProperties.GlobalOperationParameter globalOperationParameter : globalOperationParameters) { parameters.add(new ParameterBuilder() .name(globalOperationParameter.getName()) .description(globalOperationParameter.getDescription()) .modelRef(new ModelRef(globalOperationParameter.getModelRef())) .parameterType(globalOperationParameter.getParameterType()) .required(Boolean.parseBoolean(globalOperationParameter.getRequired())) .build()); } return parameters; }
Example #5
Source File: SwaggerConfig.java From spring-boot-demo-all with Apache License 2.0 | 6 votes |
@Bean public Docket defaultApi() { /** * 配置请求头参数 */ ParameterBuilder aParameterBuilder = new ParameterBuilder(); aParameterBuilder.name("Authorization").description("input the token for authentication either in the authorization field or in the token field").modelRef(new ModelRef("string")).parameterType("header").required(false).build(); ParameterBuilder aParameterBuilder1 = new ParameterBuilder(); aParameterBuilder1.name("token").description("input the token for authentication either in the authorization field or in the token field").modelRef(new ModelRef("string")).parameterType("query").required(false).build(); List<Parameter> aParameters = new ArrayList<Parameter>(); aParameters.add(aParameterBuilder.build()); aParameters.add(aParameterBuilder1.build()); return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).useDefaultResponseMessages(false).globalOperationParameters(aParameters).select() .apis(RequestHandlerSelectors.basePackage(basePackage)).paths(PathSelectors.any()).build(); }
Example #6
Source File: SwaggerConfig.java From ReCiter with Apache License 2.0 | 6 votes |
@Bean public Docket productApi() { ParameterBuilder parameterBuilder = new ParameterBuilder(); List<Parameter> parameterBuilders = new ArrayList<>(1); parameterBuilder .name("header") .description("Description of header") .modelRef(new ModelRef("string")) .parameterType("header") .required(true); parameterBuilders.add(parameterBuilder.build()); return new Docket(DocumentationType.SWAGGER_2) // .globalOperationParameters(parameterBuilders) .select() .apis(RequestHandlerSelectors.basePackage("reciter.controller")) .paths(regex("/reciter.*")) .build(); // .apiInfo(apiInfo()) // .securitySchemes(Arrays.asList(apiKey())); }
Example #7
Source File: SwaggerConfig.java From open-capacity-platform with Apache License 2.0 | 6 votes |
@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 #8
Source File: SwaggerConfig.java From open-capacity-platform with Apache License 2.0 | 6 votes |
@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 #9
Source File: SwaggerConfig.java From open-capacity-platform with Apache License 2.0 | 6 votes |
@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 #10
Source File: SwaggerConfig.java From open-capacity-platform with Apache License 2.0 | 6 votes |
@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 #11
Source File: SwaggerConfig.java From open-capacity-platform with Apache License 2.0 | 6 votes |
@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("/sms.*").apply(input) // || PathSelectors.regex("/permissions.*").apply(input) // || PathSelectors.regex("/roles.*").apply(input) || PathSelectors.regex("/test.*").apply(input) ) // .paths(PathSelectors.any()) .build().globalOperationParameters(pars); }
Example #12
Source File: RequestToPoOperationBuilder.java From jframework with Apache License 2.0 | 6 votes |
private static Parameter genPrimaryTypeDoc(Field field, String prefix, String itemTypeName) { ApiModelProperty apiModelProperty = field.getAnnotation(ApiModelProperty.class); String description = ObjectUtils.isEmpty(apiModelProperty) ? field.getName() : apiModelProperty.value(); String name = CaseUtil.snakeCase(field.getName()); boolean required = false; NotNull notNull = field.getAnnotation(NotNull.class); if (notNull != null) { required = true; } return new ParameterBuilder() .description(description) .type(new TypeResolver().resolve(field.getClass())) .name(ObjectUtils.isEmpty(prefix) ? name : prefix + "." + name) .parameterType("query") .parameterAccess("access") .required(required) .modelRef(new ModelRef(itemTypeName)) .build(); }
Example #13
Source File: SwaggerConfig.java From yshopmall with Apache License 2.0 | 6 votes |
@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 #14
Source File: SwaggerConfiguration.java From spring-cloud-yes with Apache License 2.0 | 6 votes |
@Bean public Docket customImplementation() { ParameterBuilder builder = new ParameterBuilder(); Parameter parameter = builder //参数类型支持header, cookie, body, query etc .parameterType("header") //参数名 .name("Token") .description("请输入您的JWT Token") //指定参数值的类型 .modelRef(new ModelRef("string")) .required(false) .build(); List<Parameter> parameters = Lists.newArrayList(parameter); return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage("com.itmuch")) .paths(PathSelectors.any()) .build() .apiInfo(this.apiInfo()) .globalOperationParameters(parameters); }
Example #15
Source File: SwaggerConfiguration.java From spring-cloud-yes with Apache License 2.0 | 6 votes |
@Bean public Docket customImplementation() { ParameterBuilder builder = new ParameterBuilder(); Parameter parameter = builder .parameterType("header") //参数类型支持header, cookie, body, query etc .name("Token") //参数名 .description("请输入您的JWT Token") .modelRef(new ModelRef("string"))//指定参数值的类型 .required(false) .build(); List<Parameter> parameters = Lists.newArrayList(parameter); return new Docket(DocumentationType.SWAGGER_2) // TODO: 2017/11/2 等等待配置域名 //.host() .select() .apis(RequestHandlerSelectors.basePackage("com.itmuch")) .paths(PathSelectors.any()) .build() .apiInfo(this.apiInfo()) .globalOperationParameters(parameters); }
Example #16
Source File: DefaultParamPlugin.java From BlogManagePlatform with Apache License 2.0 | 6 votes |
private void resolveApiParam(ParameterContext context) { ResolvedType resolvedType = context.resolvedMethodParameter().getParameterType(); Class<?> parameterClass = resolveParamType(resolvedType); if (parameterClass == null) { log.warn(StrUtil.concat(resolvedType.getBriefDescription(), "的类型无法被DefaultParamPlugin解析")); @SuppressWarnings("unused") int a = 1; return; } ApiModel apiModel = parameterClass.getAnnotation(ApiModel.class); if (apiModel == null) { if (!BeanUtils.isSimpleProperty(parameterClass)) { warn(context, parameterClass); } return; } ParameterBuilder builder = context.parameterBuilder(); builder.name(apiModel.description()); builder.description(descriptions.resolve(apiModel.description())); builder.allowMultiple(false); builder.allowEmptyValue(false); builder.hidden(false); builder.collectionFormat(""); builder.order(SWAGGER_PLUGIN_ORDER); }
Example #17
Source File: PageableParameterBuilderPlugin.java From jhipster with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public void apply(OperationContext context) { List<Parameter> parameters = newArrayList(); for (ResolvedMethodParameter methodParameter : context.getParameters()) { ResolvedType resolvedType = methodParameter.getParameterType(); if (pageableType.equals(resolvedType)) { ParameterContext parameterContext = new ParameterContext(methodParameter, new ParameterBuilder(), context.getDocumentationContext(), context.getGenericsNamingStrategy(), context); parameters.add(createPageParameter(parameterContext)); parameters.add(createSizeParameter(parameterContext)); parameters.add(createSortParameter(parameterContext)); context.operationBuilder().parameters(parameters); } } }
Example #18
Source File: SwaggerConfig.java From spring-cloud-demo with Apache License 2.0 | 6 votes |
@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.api.controller")) .paths(regex(".*")) .build() .globalOperationParameters(params); }
Example #19
Source File: SwaggerConfig.java From java-pay with Apache License 2.0 | 6 votes |
@Bean public Docket webApi() { 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接口文档") .apiInfo(apiInfo()) .globalOperationParameters(Collections.singletonList(parameter)) .select() .apis(RequestHandlerSelectors.basePackage("com.leone.pay.web")) .paths(PathSelectors.any()) .build(); }
Example #20
Source File: SwaggerConfig.java From java-pay with Apache License 2.0 | 6 votes |
@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 #21
Source File: Swagger2Config.java From spring-cloud-learning with MIT License | 6 votes |
@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 #22
Source File: Swagger2Config.java From spring-cloud-learning with MIT License | 6 votes |
@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 #23
Source File: SwaggerConfig.java From common-mvc with MIT License | 6 votes |
@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 #24
Source File: SwaggerConfiguration.java From token-authentication-example with Apache License 2.0 | 6 votes |
@Bean public Docket createRestApi() { ParameterBuilder parameterBuilder = new ParameterBuilder(); List<Parameter> parameters = new ArrayList<>(); parameterBuilder.name("Authorization").description("Authorization") .modelRef(new ModelRef("string")).parameterType("header") .required(false).build(); parameters.add(parameterBuilder.build()); return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage("com.example.token.controller")) .paths(PathSelectors.any()) .build() .globalOperationParameters(parameters) .apiInfo(apiInfo()); }
Example #25
Source File: Swagger2Config.java From hdw-dubbo with Apache License 2.0 | 6 votes |
private List<Parameter> setHeaderToken() { List<Parameter> pars = new ArrayList<>(); // token请求头 String testTokenValue = ""; ParameterBuilder tokenPar = new ParameterBuilder(); Parameter tokenParameter = tokenPar .name(CommonConstant.JWT_DEFAULT_TOKEN_NAME) .description("Token Request Header") .modelRef(new ModelRef("string")) .parameterType("header") .required(false) .defaultValue(testTokenValue) .build(); pars.add(tokenParameter); return pars; }
Example #26
Source File: SwaggerAutoConfiguration.java From Taroco with Apache License 2.0 | 6 votes |
private List<Parameter> buildGlobalOperationParametersFromSwaggerProperties( List<SwaggerProperties.GlobalOperationParameter> globalOperationParameters) { List<Parameter> parameters = Lists.newArrayList(); if (Objects.isNull(globalOperationParameters)) { return parameters; } for (SwaggerProperties.GlobalOperationParameter globalOperationParameter : globalOperationParameters) { parameters.add(new ParameterBuilder() .name(globalOperationParameter.getName()) .description(globalOperationParameter.getDescription()) .modelRef(new ModelRef(globalOperationParameter.getModelRef())) .parameterType(globalOperationParameter.getParameterType()) .required(Boolean.parseBoolean(globalOperationParameter.getRequired())) .build()); } return parameters; }
Example #27
Source File: SwaggerConfig.java From pig with MIT License | 6 votes |
@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 #28
Source File: SwaggerConfig.java From eladmin with Apache License 2.0 | 6 votes |
@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() .paths(Predicates.not(PathSelectors.regex("/error.*"))) .build() .globalOperationParameters(pars); }
Example #29
Source File: SwaggerConfiguration.java From fw-cloud-framework with MIT License | 6 votes |
@Bean public Docket createRestApi() { List<Parameter> operationParameters = new ArrayList<Parameter>(); ParameterBuilder parameterBuilder = new ParameterBuilder(); parameterBuilder .name("Authorization") .defaultValue( "Bearer 请求中获取heard中token参数|获取cookie中的x-access-token值") .description("Bearer 令牌值") .modelRef(new ModelRef("string")) .parameterType("header") .required(true) .build(); operationParameters.add(parameterBuilder.build()); return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) .paths(PathSelectors.any()) .build() .globalOperationParameters(operationParameters); }
Example #30
Source File: SwaggerConfig.java From spring-cloud-demo with Apache License 2.0 | 6 votes |
@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); }