springfox.documentation.spring.web.plugins.Docket Java Examples

The following examples show how to use springfox.documentation.spring.web.plugins.Docket. 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 Project: api-layer   Author: zowe   File: SwaggerConfiguration.java    License: 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 Project: DimpleBlog   Author: DimpleFeng   File: SwaggerConfig.java    License: 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 #3
Source Project: albedo   Author: somowhere   File: SwaggerAutoConfiguration.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #4
/**
 * 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()
               ));
   }
 
Example #5
Source Project: pacbot   Author: tmobile   File: SwaggerConfig.java    License: 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 #6
Source Project: api-layer   Author: zowe   File: SwaggerConfiguration.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@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()
            )
        );
}
 
Example #7
Source Project: open-capacity-platform   Author: open-capacity-platform   File: SwaggerConfig.java    License: 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 #8
Source Project: yauaa   Author: nielsbasjes   File: SwaggerConfig.java    License: Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #9
Source Project: j360-boot-app-all   Author: xuminwlt   File: SwaggerConfig.java    License: Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #10
Source Project: spring-boot-plus   Author: geekidea   File: Swagger2Config.java    License: 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 #11
Source Project: web-flash   Author: enilu   File: Swagger2Configuration.java    License: 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("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);
}
 
Example #12
Source Project: pig   Author: magicgis   File: SwaggerConfig.java    License: 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 #13
Source Project: sophia_scaffolding   Author: SophiaLeo   File: Swagger2Config.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 创建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()));

}
 
Example #14
Source Project: Learning-Path-Spring-5-End-to-End-Programming   Author: PacktPublishing   File: SwaggerConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean
public Docket documentation() {
  return new Docket(DocumentationType.SWAGGER_2)
      .select()
      .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
      .paths(PathSelectors.any())
      .build();
}
 
Example #15
Source Project: alcor   Author: futurewei-cloud   File: SwaggerConfig.java    License: 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.any())
            .paths(PathSelectors.regex("(?!/error).+"))
            .paths(PathSelectors.regex("(?!/actuator).+"))
            .build();
}
 
Example #16
Source Project: ticket   Author: qianxunclub   File: SwaggerConfig.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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();
}
 
Example #17
Source Project: mall-learning   Author: macrozheng   File: Swagger2Config.java    License: Apache License 2.0 5 votes vote down vote up
@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();
    }
 
Example #18
Source Project: openapi-generator   Author: OpenAPITools   File: OpenAPIDocumentationConfig.java    License: Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #19
Source Project: mall   Author: macrozheng   File: Swagger2Config.java    License: 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.macro.mall.demo"))
            .paths(PathSelectors.any())
            .build();
}
 
Example #20
Source Project: sample-zuul-swagger2   Author: SpringCloud   File: ClientAApplication.java    License: Apache License 2.0 5 votes vote down vote up
@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()
			);
}
 
Example #21
Source Project: withme3.0   Author: IcedSoul   File: SwaggerConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("cn.icedsoul.offlinemessageservice"))
            .paths(PathSelectors.any())
            .build();
}
 
Example #22
Source Project: mall-learning   Author: macrozheng   File: Swagger2Config.java    License: Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #23
Source Project: spring-boot-tutorials   Author: TFdream   File: Swagger2Config.java    License: 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(BASE_PACKAGE))
            .paths(PathSelectors.any())
            .build();
}
 
Example #24
Source Project: spring-http-patch-example   Author: countrogue   File: SwaggerConfig.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Bean
public Docket customImplementation(){
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
                .paths(or(regex("/api/v1.*")))
                .build()
            .apiInfo(apiInfo());
}
 
Example #25
Source Project: Spring   Author: iooifun   File: SwaggerConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public Docket api() {
	return new Docket(DocumentationType.SWAGGER_2)
			.apiInfo(DEFAULT_API_INFO)
			.produces(DEFAULT_PRODUCES_AND_CONSUMES)
			.consumes(DEFAULT_PRODUCES_AND_CONSUMES);
}
 
Example #26
Source Project: DBus   Author: BriData   File: SwaggerConfig.java    License: Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #27
Source Project: Lottor   Author: keets2012   File: TxManagerConfiguration.java    License: 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.blueskykong.lottor.server.controller"))
            .paths(PathSelectors.any())
            .build();
}
 
Example #28
Source Project: mall   Author: macrozheng   File: Swagger2Config.java    License: 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.macro.mall.search.controller"))
            .paths(PathSelectors.any())
            .build();
}
 
Example #29
Source Project: coditori   Author: coditori   File: SwaggerConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.massoudafrashteh.code.controller"))
            .paths(PathSelectors.any())
            .build();
}
 
Example #30
Source Project: restful-booker-platform   Author: mwinteringham   File: SwaggerConfig.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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();
}