com.ape9527.core.config.SwaggerConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ape-core Show documentation
Show all versions of ape-core Show documentation
Ape low code platform core module
The newest version!
package com.ape9527.core.config;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
import java.util.List;
/**
* swagger配置文件
*
* @author YuanShuai[[email protected]]
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
List pars = new ArrayList();
ParameterBuilder tokenPar = new ParameterBuilder();
tokenPar.name("Authorization").description("请求令牌").modelRef(new ModelRef("String")).parameterType("header").required(false).build();
pars.add(tokenPar.build());
ParameterBuilder tokenPar2 = new ParameterBuilder();
tokenPar2.name("NotCryptFlag").description("不加密请求标志(随便填点什么都可以)").modelRef(new ModelRef("String")).parameterType("header").required(true).defaultValue("true").build();
pars.add(tokenPar2.build());
return new Docket(DocumentationType.SWAGGER_2)
// 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息)
.apiInfo(apiInfo())
// 设置哪些接口暴露给Swagger展示
.select()
// 扫描所有有注解的api,用这种方式更灵活
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
// 扫描指定包中的swagger注解
// .apis(RequestHandlerSelectors.basePackage("com.ape9527.controller"))
// 扫描所有
// .apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build().globalOperationParameters(pars);
}
// 构建 api 文档的详细信息
private ApiInfo apiInfo(){
// 用ApiInfoBuilder进行定制
return new ApiInfoBuilder()
// 设置标题
.title("接口文档")
// 描述
// .description("描述")
// 作者信息
// .contact(new Contact("猿帅","url","email"))
// 版本
.version("版本号:1.0") .build();
}
}