You've already forked FrameTour-BE
Init
This commit is contained in:
72
src/main/java/com/ycwl/basic/config/SwaggerConfig.java
Normal file
72
src/main/java/com/ycwl/basic/config/SwaggerConfig.java
Normal file
@ -0,0 +1,72 @@
|
||||
package com.ycwl.basic.config;
|
||||
|
||||
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.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
|
||||
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"))
|
||||
.paths(PathSelectors.any())
|
||||
.build()
|
||||
.globalOperationParameters(getGlobalRequestParameters());
|
||||
}
|
||||
|
||||
/**
|
||||
* Swagger 的描述信息
|
||||
*/
|
||||
public ApiInfo apiInfo() {
|
||||
|
||||
return new ApiInfoBuilder()
|
||||
.title("city-investment-smart-park")
|
||||
.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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user