| | |
| | | package com.ruoyi.framework.config; |
| | | |
| | | import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.framework.config.properties.SwaggerProperties; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import springfox.documentation.builders.ApiInfoBuilder; |
| | |
| | | @Configuration |
| | | @EnableSwagger2 |
| | | @EnableKnife4j |
| | | @ConditionalOnClass({Docket.class, ApiInfoBuilder.class}) |
| | | @ConditionalOnProperty(prefix = "swagger", value = "enable", matchIfMissing = true) |
| | | public class SwaggerConfig { |
| | | /** |
| | | * 系统基础配置 |
| | | */ |
| | | |
| | | @Autowired |
| | | private RuoYiConfig ruoyiConfig; |
| | | |
| | | /** |
| | | * 标题 |
| | | */ |
| | | @Value("${swagger.title}") |
| | | private String title; |
| | | |
| | | /** |
| | | * 描述 |
| | | */ |
| | | @Value("${swagger.description}") |
| | | private String description; |
| | | |
| | | /** |
| | | * 版本 |
| | | */ |
| | | @Value("${swagger.version}") |
| | | private String version; |
| | | private SwaggerProperties swaggerProperties; |
| | | |
| | | /** |
| | | * 创建API |
| | |
| | | @Bean |
| | | public Docket createRestApi() { |
| | | return new Docket(DocumentationType.SWAGGER_2) |
| | | .enable(swaggerProperties.getEnabled()) |
| | | // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息) |
| | | .apiInfo(apiInfo()) |
| | | // 设置哪些接口暴露给Swagger展示 |
| | |
| | | */ |
| | | private ApiInfo apiInfo() { |
| | | // 用ApiInfoBuilder进行定制 |
| | | SwaggerProperties.Contact contact = swaggerProperties.getContact(); |
| | | return new ApiInfoBuilder() |
| | | // 设置标题 |
| | | .title(title) |
| | | .title(swaggerProperties.getTitle()) |
| | | // 描述 |
| | | .description(description) |
| | | .description(swaggerProperties.getDescription()) |
| | | // 作者信息 |
| | | .contact(new Contact(ruoyiConfig.getName(), null, null)) |
| | | .contact(new Contact(contact.getName(), contact.getUrl(), contact.getEmail())) |
| | | // 版本 |
| | | .version(version) |
| | | .version(swaggerProperties.getVersion()) |
| | | .build(); |
| | | } |
| | | } |