类springfox.documentation.spring.web.plugins.Docket源码实例Demo

下面列出了怎么用springfox.documentation.spring.web.plugins.Docket的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: 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);
}
 
源代码2 项目: albedo   文件: SwaggerAutoConfiguration.java
/**
 * Springfox configuration for the API Swagger docs.
 *
 * @param swaggerCustomizers Swagger customizers
 * @param alternateTypeRules alternate type rules
 * @return the Swagger Springfox configuration
 */
@Bean
@ConditionalOnMissingBean(name = "swaggerSpringfoxApiDocket")
public Docket swaggerSpringfoxApiDocket(List<SwaggerCustomizer> swaggerCustomizers,
										ObjectProvider<AlternateTypeRule[]> alternateTypeRules) {
	log.debug(STARTING_MESSAGE);
	StopWatch watch = new StopWatch();
	watch.start();

	Docket docket = createDocket();

	// Apply all SwaggerCustomizers orderly.
	swaggerCustomizers.forEach(customizer -> customizer.customize(docket));

	// Add all AlternateTypeRules if available in spring bean factory.
	// Also you can add your rules in a customizer bean above.
	Optional.ofNullable(alternateTypeRules.getIfAvailable()).ifPresent(docket::alternateTypeRules);

	watch.stop();
	log.debug(STARTED_MESSAGE, watch.getTotalTimeMillis());
	return docket;
}
 
/**
 * 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()
               ));
   }
 
源代码4 项目: pacbot   文件: SwaggerConfig.java
@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);
}
 
源代码5 项目: api-layer   文件: SwaggerConfiguration.java
@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
        .select()
        .apis(RequestHandlerSelectors.any())
        .paths(PathSelectors.ant("/api/v1/**"))
        .build()
        .apiInfo(
            new ApiInfo(
                apiTitle,
                apiDescription,
                apiVersion,
                null,
                null,
                null,
                null,
                Collections.emptyList()
            )
        );
}
 
源代码6 项目: 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);
}
 
源代码7 项目: 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()
            )
        );
}
 
源代码8 项目: yauaa   文件: SwaggerConfig.java
@Bean
public Docket api() {

    final ArrayList<Response> responseMessages = new ArrayList<>();
    responseMessages.add(new ResponseBuilder()
        .code("200")
        .description("Successfully parsed the provided input")
        .build());
    responseMessages.add(new ResponseBuilder()
        .code("503")
        .description("Internal error, or Yauaa is currently still busy starting up.")
        .build());

    return new Docket(DocumentationType.SWAGGER_2)
        .groupName("yauaa-v1")
        .select()
        .apis(withMethodAnnotation(ApiOperation.class))
        .build()
        .globalResponses(GET, responseMessages)
        .globalResponses(POST, responseMessages)
        .apiInfo(apiInfo());
}
 
源代码9 项目: j360-boot-app-all   文件: SwaggerConfig.java
@Bean
public Docket webApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .groupName("api")
            //.host()
            .genericModelSubstitutes(DeferredResult.class)
            //.genericModelSubstitutes(ResponseEntity.class)
            .useDefaultResponseMessages(false)
            .forCodeGeneration(false)
            .pathMapping("/")
            .select()
            //.paths(PathSelectors.regex("/api"))//过滤的接口
            .build()
            .apiInfo(webApiInfo())
            .securitySchemes(securitySchemes())
            .securityContexts(securityContexts());
}
 
源代码10 项目: 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;
}
 
源代码11 项目: web-flash   文件: Swagger2Configuration.java
@Bean
public Docket createRestApi() {
    //添加head参数start
    ParameterBuilder tokenPar = new ParameterBuilder();
    List<Parameter> pars = new ArrayList<Parameter>();
    tokenPar.name("Authorization").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);
}
 
源代码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 项目: sophia_scaffolding   文件: Swagger2Config.java
/**
 * 创建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()));

}
 
@Bean
public Docket documentation() {
  return new Docket(DocumentationType.SWAGGER_2)
      .select()
      .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
      .paths(PathSelectors.any())
      .build();
}
 
源代码15 项目: 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();
}
 
源代码16 项目: ticket   文件: SwaggerConfig.java
@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .enable(this.getEnabled())
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage(this.getWebBasePackage()))
            .paths(not(regex("/error.*")))
            .build();
}
 
源代码17 项目: mall-learning   文件: Swagger2Config.java
@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();
    }
 
@Bean
public Docket customImplementation(){
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
                .apis(RequestHandlerSelectors.basePackage("org.openapitools.codegen.online.api"))
                .build()
            .forCodeGeneration(true)
            .directModelSubstitute(java.time.LocalDate.class, java.sql.Date.class)
            .directModelSubstitute(java.time.OffsetDateTime.class, java.util.Date.class)
            .directModelSubstitute(JsonNode.class, java.lang.Object.class)
            .ignoredParameterTypes(Resource.class)
            .ignoredParameterTypes(InputStream.class)
            .apiInfo(apiInfo());
}
 
源代码19 项目: mall   文件: Swagger2Config.java
@Bean
public Docket createRestApi(){
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.macro.mall.demo"))
            .paths(PathSelectors.any())
            .build();
}
 
源代码20 项目: sample-zuul-swagger2   文件: ClientAApplication.java
@Bean
public Docket swaggerPersonApi10() {
	return new Docket(DocumentationType.SWAGGER_2)
			.select()
			.apis(RequestHandlerSelectors.basePackage("cn.springcloud.sample.controller"))
			.paths(PathSelectors.any())
			.build()
			.apiInfo(
					new ApiInfoBuilder()
					.version("1.0")
					.title("Original Service API")
					.description("Original Service API v1.0")
					.build()
			);
}
 
源代码21 项目: withme3.0   文件: SwaggerConfig.java
@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("cn.icedsoul.offlinemessageservice"))
            .paths(PathSelectors.any())
            .build();
}
 
源代码22 项目: mall-learning   文件: Swagger2Config.java
@Bean
public Docket createRestApi(){
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            //为当前包下controller生成API文档
            .apis(RequestHandlerSelectors.basePackage("com.macro.mall.tiny.controller"))
            .paths(PathSelectors.any())
            .build()
            //添加登录认证
            .securitySchemes(securitySchemes())
            .securityContexts(securityContexts());
}
 
源代码23 项目: spring-boot-tutorials   文件: Swagger2Config.java
@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            //为当前包路径
            .apis(RequestHandlerSelectors.basePackage(BASE_PACKAGE))
            .paths(PathSelectors.any())
            .build();
}
 
源代码24 项目: spring-http-patch-example   文件: SwaggerConfig.java
@Bean
public Docket customImplementation(){
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
                .paths(or(regex("/api/v1.*")))
                .build()
            .apiInfo(apiInfo());
}
 
源代码25 项目: Spring   文件: SwaggerConfig.java
@Bean
public Docket api() {
	return new Docket(DocumentationType.SWAGGER_2)
			.apiInfo(DEFAULT_API_INFO)
			.produces(DEFAULT_PRODUCES_AND_CONSUMES)
			.consumes(DEFAULT_PRODUCES_AND_CONSUMES);
}
 
源代码26 项目: 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());
}
 
源代码27 项目: Lottor   文件: TxManagerConfiguration.java
@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.blueskykong.lottor.server.controller"))
            .paths(PathSelectors.any())
            .build();
}
 
源代码28 项目: mall   文件: Swagger2Config.java
@Bean
public Docket createRestApi(){
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.macro.mall.search.controller"))
            .paths(PathSelectors.any())
            .build();
}
 
源代码29 项目: coditori   文件: SwaggerConfig.java
@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.massoudafrashteh.code.controller"))
            .paths(PathSelectors.any())
            .build();
}
 
源代码30 项目: 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();
}