|
|
@@ -1,8 +1,8 @@
|
|
|
package cn.hfln.framework.knife4j.doc.gateway;
|
|
|
|
|
|
import cn.hfln.framework.knife4j.doc.properties.DocProperties;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
+import lombok.Getter;
|
|
|
+import lombok.Setter;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
@@ -17,23 +17,15 @@ import java.util.Map;
|
|
|
@Component
|
|
|
public class SwaggerAggregator {
|
|
|
|
|
|
- private static final Logger log = LoggerFactory.getLogger(SwaggerAggregator.class);
|
|
|
|
|
|
private final DocProperties docProperties;
|
|
|
|
|
|
public SwaggerAggregator(DocProperties docProperties) {
|
|
|
this.docProperties = docProperties;
|
|
|
- log.info("=== SwaggerAggregator 初始化 ===");
|
|
|
- log.info("DocProperties.gateway: {}", docProperties.getGateway());
|
|
|
if (docProperties.getGateway() != null && docProperties.getGateway().getServices() != null) {
|
|
|
- log.info("网关聚合服务数量: {}", docProperties.getGateway().getServices().size());
|
|
|
for (int i = 0; i < docProperties.getGateway().getServices().size(); i++) {
|
|
|
DocProperties.ServiceConfig service = docProperties.getGateway().getServices().get(i);
|
|
|
- log.info(" [{}] 服务: name={}, url={}, description={}",
|
|
|
- i, service.getName(), service.getUrl(), service.getDescription());
|
|
|
}
|
|
|
- } else {
|
|
|
- log.warn("未配置网关聚合服务");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -41,18 +33,9 @@ public class SwaggerAggregator {
|
|
|
* 获取聚合的 Swagger 配置
|
|
|
*/
|
|
|
public Map<String, Object> getSwaggerConfig() {
|
|
|
- log.info("=== 构建 Swagger 聚合配置 ===");
|
|
|
Map<String, Object> config = new HashMap<>(8);
|
|
|
List<ServiceUrl> serviceUrls = buildServiceUrls();
|
|
|
config.put("urls", serviceUrls);
|
|
|
-
|
|
|
- log.info("聚合配置构建完成,分组数量: {}", serviceUrls.size());
|
|
|
- for (int i = 0; i < serviceUrls.size(); i++) {
|
|
|
- ServiceUrl serviceUrl = serviceUrls.get(i);
|
|
|
- log.info(" [{}] 分组: name={}, url={}, description={}",
|
|
|
- i, serviceUrl.getName(), serviceUrl.getUrl(), serviceUrl.getDescription());
|
|
|
- }
|
|
|
-
|
|
|
return config;
|
|
|
}
|
|
|
|
|
|
@@ -61,7 +44,6 @@ public class SwaggerAggregator {
|
|
|
* 直接使用配置文件中的 url,不做任何自动转换
|
|
|
*/
|
|
|
private List<ServiceUrl> buildServiceUrls() {
|
|
|
- log.info("=== 构建服务 URL 列表 ===");
|
|
|
List<ServiceUrl> serviceUrls = new ArrayList<>();
|
|
|
if (docProperties.getGateway() != null && docProperties.getGateway().getServices() != null) {
|
|
|
for (DocProperties.ServiceConfig serviceConfig : docProperties.getGateway().getServices()) {
|
|
|
@@ -71,18 +53,16 @@ public class SwaggerAggregator {
|
|
|
serviceConfig.getDescription()
|
|
|
);
|
|
|
serviceUrls.add(serviceUrl);
|
|
|
- log.info(" 添加服务分组: name={}, url={}", serviceConfig.getName(), serviceConfig.getUrl());
|
|
|
}
|
|
|
- } else {
|
|
|
- log.warn("docProperties.getGateway().getServices() 为空,无法构建服务列表");
|
|
|
}
|
|
|
- log.info("服务 URL 列表构建完成,共 {} 个服务", serviceUrls.size());
|
|
|
return serviceUrls;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 服务 URL 信息
|
|
|
*/
|
|
|
+ @Setter
|
|
|
+ @Getter
|
|
|
public static class ServiceUrl {
|
|
|
private String name;
|
|
|
private String url;
|
|
|
@@ -99,28 +79,5 @@ public class SwaggerAggregator {
|
|
|
this.description = description;
|
|
|
}
|
|
|
|
|
|
- public String getName() {
|
|
|
- return name;
|
|
|
- }
|
|
|
-
|
|
|
- public void setName(String name) {
|
|
|
- this.name = name;
|
|
|
- }
|
|
|
-
|
|
|
- public String getUrl() {
|
|
|
- return url;
|
|
|
- }
|
|
|
-
|
|
|
- public void setUrl(String url) {
|
|
|
- this.url = url;
|
|
|
- }
|
|
|
-
|
|
|
- public String getDescription() {
|
|
|
- return description;
|
|
|
- }
|
|
|
-
|
|
|
- public void setDescription(String description) {
|
|
|
- this.description = description;
|
|
|
- }
|
|
|
}
|
|
|
}
|