|
|
@ -3,6 +3,7 @@ package com.ruoyi.framework.config;
|
|
|
|
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
|
|
|
|
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
|
|
|
|
import com.ruoyi.framework.config.properties.SwaggerProperties;
|
|
|
|
import com.ruoyi.framework.config.properties.SwaggerProperties;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
|
|
import io.swagger.models.auth.In;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
@ -13,7 +14,6 @@ import springfox.documentation.service.*;
|
|
|
|
import springfox.documentation.spi.DocumentationType;
|
|
|
|
import springfox.documentation.spi.DocumentationType;
|
|
|
|
import springfox.documentation.spi.service.contexts.SecurityContext;
|
|
|
|
import springfox.documentation.spi.service.contexts.SecurityContext;
|
|
|
|
import springfox.documentation.spring.web.plugins.Docket;
|
|
|
|
import springfox.documentation.spring.web.plugins.Docket;
|
|
|
|
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
@ -24,7 +24,6 @@ import java.util.List;
|
|
|
|
* @author Lion Li
|
|
|
|
* @author Lion Li
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
@EnableSwagger2
|
|
|
|
|
|
|
|
@EnableKnife4j
|
|
|
|
@EnableKnife4j
|
|
|
|
public class SwaggerConfig {
|
|
|
|
public class SwaggerConfig {
|
|
|
|
|
|
|
|
|
|
|
@ -36,7 +35,7 @@ public class SwaggerConfig {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
public Docket createRestApi() {
|
|
|
|
public Docket createRestApi() {
|
|
|
|
return new Docket(DocumentationType.SWAGGER_2)
|
|
|
|
return new Docket(DocumentationType.OAS_30)
|
|
|
|
.enable(swaggerProperties.getEnabled())
|
|
|
|
.enable(swaggerProperties.getEnabled())
|
|
|
|
// 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息)
|
|
|
|
// 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息)
|
|
|
|
.apiInfo(apiInfo())
|
|
|
|
.apiInfo(apiInfo())
|
|
|
@ -60,7 +59,7 @@ public class SwaggerConfig {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private List<SecurityScheme> securitySchemes() {
|
|
|
|
private List<SecurityScheme> securitySchemes() {
|
|
|
|
List<SecurityScheme> apiKeyList = new ArrayList<SecurityScheme>();
|
|
|
|
List<SecurityScheme> apiKeyList = new ArrayList<SecurityScheme>();
|
|
|
|
apiKeyList.add(new ApiKey("Authorization", "Authorization", "header"));
|
|
|
|
apiKeyList.add(new ApiKey("Authorization", "Authorization", In.HEADER.toValue()));
|
|
|
|
return apiKeyList;
|
|
|
|
return apiKeyList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -72,7 +71,7 @@ public class SwaggerConfig {
|
|
|
|
securityContexts.add(
|
|
|
|
securityContexts.add(
|
|
|
|
SecurityContext.builder()
|
|
|
|
SecurityContext.builder()
|
|
|
|
.securityReferences(defaultAuth())
|
|
|
|
.securityReferences(defaultAuth())
|
|
|
|
.forPaths(PathSelectors.regex("^(?!auth).*$"))
|
|
|
|
.operationSelector(o -> o.requestMappingPattern().matches("/.*"))
|
|
|
|
.build());
|
|
|
|
.build());
|
|
|
|
return securityContexts;
|
|
|
|
return securityContexts;
|
|
|
|
}
|
|
|
|
}
|
|
|
|