| | |
| | | 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(); |
| | | } |
| | | } |