update 优化 默认使用服务名去除前缀当Path 支持自定义Path

2.X
疯狂的狮子Li 3 years ago
parent 6c2784a57f
commit 7987cd6d3d

@ -257,6 +257,10 @@ swagger:
type: APIKEY
in: HEADER
name: ${sa-token.token-name}
# 服务文档路径映射 参考 gateway router 配置
# 默认为服务名去除前缀转换为path 此处填特殊的配置
service-mapping:
ruoyi-gen: /code
# seata配置
seata:

@ -23,6 +23,7 @@ import org.springframework.context.annotation.Bean;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
@ -90,9 +91,22 @@ public class SwaggerAutoConfiguration {
*/
@Bean
public OpenApiCustomiser openApiCustomiser() {
// 如果服务的自定义 Path 不存在 则采用默认去除前缀当 Path
Map<String, String> serviceMapping = swaggerProperties.getServiceMapping();
String appPath;
if (serviceMapping.containsKey(appName)) {
appPath = serviceMapping.get(appName);
} else {
appPath = "/" + StringUtils.substring(appName, appName.indexOf("-") + 1);
}
String contextPath = serverProperties.getServlet().getContextPath();
String appPath = "/" + StringUtils.substring(appName, appName.indexOf("-") + 1);
String finalContextPath = StringUtils.isBlank(contextPath) || "/".equals(contextPath) ? appPath : appPath + contextPath;
String finalContextPath;
if (StringUtils.isBlank(contextPath) || "/".equals(contextPath)) {
finalContextPath = appPath;
} else {
finalContextPath = appPath + contextPath;
}
// 对所有路径增加前置上下文路径
return openApi -> {
Paths oldPaths = openApi.getPaths();

@ -11,6 +11,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import java.util.List;
import java.util.Map;
/**
* swagger
@ -55,6 +56,12 @@ public class SwaggerProperties {
@NestedConfigurationProperty
private Components components = null;
/**
* gateway router
* path
*/
private Map<String, String> serviceMapping = null;
/**
* <p>
*

Loading…
Cancel
Save