springfox.documentation.schema.ModelRef Java Examples

The following examples show how to use springfox.documentation.schema.ModelRef. 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 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 #2
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("/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 #3
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 #4
Source File: SwaggerConfig.java    From tutorials with MIT License 6 votes vote down vote up
@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2).select()
        .apis(RequestHandlerSelectors.basePackage("com.baeldung.web.controller"))
        .paths(PathSelectors.ant("/foos/*"))
        .build()
        .apiInfo(apiInfo())
        .useDefaultResponseMessages(false)
        .globalResponseMessage(RequestMethod.GET, newArrayList(new ResponseMessageBuilder().code(500)
            .message("500 message")
            .responseModel(new ModelRef("Error"))
            .build(),
            new ResponseMessageBuilder().code(403)
                .message("Forbidden!!!!!")
                .build()));
}
 
Example #5
Source File: SwaggerConfig.java    From spring-boot-demo-all with Apache License 2.0 6 votes vote down vote up
@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: SwaggerAutoConfiguration.java    From microservices-platform with Apache License 2.0 6 votes vote down vote up
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 #7
Source File: SwaggerConfig.java    From ReCiter with Apache License 2.0 6 votes vote down vote up
@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 #8
Source File: SwaggerConfig.java    From NFVO with Apache License 2.0 6 votes vote down vote up
@Bean
public Docket myApi() {
  return new Docket(DocumentationType.SWAGGER_2)
      .apiInfo(apiInfo())
      .select()
      .apis(RequestHandlerSelectors.any())
      .paths(paths())
      .build()
      .globalOperationParameters(
          newArrayList(
              new ParameterBuilder()
                  .name("Authorization: Bearer")
                  .description("Authorization Token")
                  .modelRef(new ModelRef("string"))
                  .parameterType("header")
                  .required(true)
                  .build()));
}
 
Example #9
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 #10
Source File: SwaggerConfiguration.java    From spring-cloud-yes with Apache License 2.0 6 votes vote down vote up
@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 #11
Source File: SwaggerConfiguration.java    From spring-cloud-yes with Apache License 2.0 6 votes vote down vote up
@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 #12
Source File: Swagger2Configuration.java    From flash-waimai with MIT License 6 votes vote down vote up
@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 #13
Source File: SwaggerAutoConfiguration.java    From spring-boot-starter-swagger with Apache License 2.0 6 votes vote down vote up
private List<Parameter> buildGlobalOperationParametersFromSwaggerProperties(
        List<SwaggerProperties.GlobalOperationParameter> globalOperationParameters) {
    List<Parameter> parameters = 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 #14
Source File: SwaggerConfig.java    From java-pay with Apache License 2.0 6 votes vote down vote up
@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 #15
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 #16
Source File: Swagger2Config.java    From springboot-seed with MIT License 6 votes vote down vote up
@Bean
public Docket createRestApi() {
    ParameterBuilder ticketPar = new ParameterBuilder();
    List<Parameter> parameters = new ArrayList<>();
    ticketPar.name("Authorization").description("Bearer token")
            .modelRef(new ModelRef("string")).parameterType("header")
            .required(false).build();
    parameters.add(ticketPar.build());
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.wind.web.controller"))
            .paths(PathSelectors.any())
            .build()
            .globalOperationParameters(parameters);
}
 
Example #17
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 #18
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 #19
Source File: SwaggerConfig.java    From pacbot with Apache License 2.0 6 votes vote down vote up
@Bean
public Docket userApi() {

	List<ResponseMessage> list = new java.util.ArrayList<>();
	list.add(new ResponseMessageBuilder().code(500).message("500 message").responseModel(new ModelRef("Result"))
			.build());
	list.add(new ResponseMessageBuilder().code(401).message("Unauthorized").responseModel(new ModelRef("Result"))
			.build());
	list.add(new ResponseMessageBuilder().code(406).message("Not Acceptable").responseModel(new ModelRef("Result"))
			.build());

	return new Docket(DocumentationType.SWAGGER_2)
		.apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage("com.tmobile.pacman"))
		.paths(PathSelectors.any()).build()
		.securitySchemes(chooseSecuritSchema())
		.securityContexts(chooseSecurityContext())
		.globalResponseMessage(RequestMethod.GET, list).globalResponseMessage(RequestMethod.POST, list);
}
 
Example #20
Source File: SwaggerConfiguration.java    From token-authentication-example with Apache License 2.0 6 votes vote down vote up
@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 #21
Source File: Swagger2Config.java    From hdw-dubbo with Apache License 2.0 6 votes vote down vote up
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 #22
Source File: SwaggerAutoConfiguration.java    From Taroco with Apache License 2.0 6 votes vote down vote up
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 #23
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 #24
Source File: SwaggerConfig.java    From eladmin 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()
            .paths(Predicates.not(PathSelectors.regex("/error.*")))
            .build()
            .globalOperationParameters(pars);
}
 
Example #25
Source File: SwaggerConfiguration.java    From fw-cloud-framework with MIT License 6 votes vote down vote up
@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 #26
Source File: CoreConfig.java    From oauth-boot with MIT License 6 votes vote down vote up
/**
 * Could not resolve view with name 'forward:/oauth/confirm_access' in servlet with name 'dispatcherServlet'
 *
 */
/*@Override
protected void configureViewResolvers(ViewResolverRegistry registry) {
    registry.viewResolver(new InternalResourceViewResolver());
}*/

@Bean
public Docket docket() {

    ParameterBuilder builder = new ParameterBuilder();
    List<Parameter> parameters = new ArrayList<>();

    builder.name("Authorization").description("token").modelRef(new ModelRef("string"))
            .parameterType("header")
            .required(false)
            .build();
    parameters.add(builder.build());

    return new Docket(DocumentationType.SWAGGER_2)
            .globalOperationParameters(parameters)
            .apiInfo(this.apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("club.yuit.oauth.boot.controller"))
            .paths(PathSelectors.any())
            .build();
}
 
Example #27
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 #28
Source File: SwaggerConfig.java    From zheshiyigeniubidexiangmu 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 #29
Source File: SwaggerConfig.java    From zheshiyigeniubidexiangmu 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 #30
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.api.controller"))
            .paths(regex(".*"))
            .build()
            .globalOperationParameters(params);
}