123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package com.primeton.dgs.kernel.core.configure;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import springfox.documentation.builders.ApiInfoBuilder;
- import springfox.documentation.builders.PathSelectors;
- import springfox.documentation.builders.RequestHandlerSelectors;
- import springfox.documentation.service.ApiInfo;
- import springfox.documentation.service.Contact;
- import springfox.documentation.spi.DocumentationType;
- import springfox.documentation.spring.web.plugins.Docket;
- import springfox.documentation.swagger2.annotations.EnableSwagger2;
- import java.util.Optional;
- /**
- * <pre>
- *
- * Created by zhaopx.
- * User: zhaopx
- * Date: 2020/8/27
- * Time: 15:27
- *
- * </pre>
- *
- * @author zhaopx
- */
- @Configuration //必须存在
- @EnableSwagger2 //必须存在
- @ConditionalOnProperty(name = "bftconsole.swagger.enable", havingValue = "true", matchIfMissing = true)
- public class SwaggerConfig {
- @Value("${swagger.group}")
- private String groupName;
- @Value("${swagger.title}")
- private String title;
- @Value("${swagger.description}")
- private String description;
- @Value("${swagger.creator}")
- private String creator;
- @Value("${swagger.version}")
- private String version;
- @Value("${swagger.basepackage}")
- private String basepackage;
- @Bean
- public Docket docket() {
- return new Docket(DocumentationType.SWAGGER_2).groupName(groupName).apiInfo(apiInfo()).select()
- // 必须扫描实现类所在的包
- .apis(RequestHandlerSelectors.basePackage(basepackage)).paths(PathSelectors.any()).build();
- }
- // 构建api文档的详细信息函数
- private ApiInfo apiInfo() {
- return new ApiInfoBuilder()
- // 页面标题
- .title(title)
- // 创建人
- .contact(new Contact(creator, "http://www.primeton.com/" + groupName, "" ))
- // 版本号
- .version(version)
- // 描述
- .description(description).build();
- }
- }
|