75 lines
2.4 KiB
Java
75 lines
2.4 KiB
Java
package com.ycwl.basic.config;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Profile;
|
|
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.Contact;
|
|
import springfox.documentation.service.Parameter;
|
|
import springfox.documentation.spi.DocumentationType;
|
|
import springfox.documentation.spring.web.plugins.Docket;
|
|
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* Swagger 配置类
|
|
* 原生: /swagger-ui.html
|
|
* 美化: /doc.html
|
|
*/
|
|
@Configuration
|
|
@EnableSwagger2WebMvc
|
|
@Profile({"!prod"})
|
|
public class SwaggerConfig {
|
|
|
|
/**
|
|
* Swagger 实例 Bean 是 Docket, 所以通过配置 Docket 实例来配置 Swagger
|
|
*/
|
|
@Bean
|
|
public Docket docket() {
|
|
|
|
return new Docket(DocumentationType.SWAGGER_2)
|
|
// 展示在 Swagger 页面上的自定义工程描述信息
|
|
.apiInfo(apiInfo())
|
|
// 选择展示哪些接口
|
|
.select()
|
|
//只有com.zcy.e.firstaid包内的才去展示
|
|
.apis(RequestHandlerSelectors.basePackage("com.ycwl.basic.controller.mobile"))
|
|
.paths(PathSelectors.any())
|
|
.build()
|
|
.globalOperationParameters(getGlobalRequestParameters());
|
|
}
|
|
|
|
/**
|
|
* Swagger 的描述信息
|
|
*/
|
|
public ApiInfo apiInfo() {
|
|
|
|
return new ApiInfoBuilder()
|
|
.title("liuyin-re")
|
|
.description("流影重构")
|
|
.contact(new Contact("ycwl", "www.xxx.com", "xxxxxxxxx.com"))
|
|
.version("1.0")
|
|
.build();
|
|
}
|
|
|
|
private List<Parameter> getGlobalRequestParameters() {
|
|
List<Parameter> parameters = new ArrayList<>();
|
|
parameters.add(new ParameterBuilder()
|
|
.name("token")
|
|
.description("登录令牌")
|
|
.parameterType("header")
|
|
.modelRef(new ModelRef("String"))
|
|
.required(true)
|
|
.build());
|
|
return parameters;
|
|
}
|
|
|
|
}
|