From 0f83b53a4b5c7f84981cc9a81d4e88ab1560226a Mon Sep 17 00:00:00 2001 From: gongzhongqiang Date: Thu, 10 Aug 2023 17:25:35 +0800 Subject: [PATCH 1/4] [ISSUE #4988] Fix swagger doc registered appName use contextPath --- .../service/manager/impl/PullSwaggerDocServiceImpl.java | 6 ++++-- .../service/manager/impl/RegisterApiDocServiceImpl.java | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/PullSwaggerDocServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/PullSwaggerDocServiceImpl.java index 1f2606140c57..2ca4e34b3438 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/PullSwaggerDocServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/PullSwaggerDocServiceImpl.java @@ -24,6 +24,8 @@ import java.util.Objects; import java.util.Set; import javax.annotation.Resource; + +import io.vertx.core.json.Json; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; @@ -123,7 +125,7 @@ private boolean canPull(final UpstreamInstance instance, final TagVO tagVO) { } private TagVO saveTagVOAndAcquireLock(final UpstreamInstance instance) { - List tagVOList = tagService.findByQuery(instance.getContextPath(), AdminConstants.TAG_ROOT_PARENT_ID); + List tagVOList = tagService.findByQuery(instance.getClusterName(), AdminConstants.TAG_ROOT_PARENT_ID); if (CollectionUtils.isNotEmpty(tagVOList)) { TagVO tagVO = tagVOList.get(0); TagDO.TagExt tagExt = convertTagExt(tagVO.getExt()); @@ -142,7 +144,7 @@ private TagVO saveTagVOAndAcquireLock(final UpstreamInstance instance) { private TagVO createRootTagAndAcquireLock(final UpstreamInstance instance) { TagDTO tagDTO = new TagDTO(); tagDTO.setTagDesc(instance.getClusterName()); - tagDTO.setName(instance.getContextPath()); + tagDTO.setName(instance.getClusterName()); tagDTO.setParentTagId(AdminConstants.TAG_ROOT_PARENT_ID); TagDO.TagExt tagExt = new TagDO.TagExt(); tagExt.setDocLock(this.generateDocLock()); diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/RegisterApiDocServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/RegisterApiDocServiceImpl.java index 020988a3ed7e..5b7064b491fb 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/RegisterApiDocServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/RegisterApiDocServiceImpl.java @@ -60,6 +60,8 @@ public void registerApiDocument(final ApiDocRegisterDTO apiDocRegisterDTO) { tags = apiDocRegisterDTO.getTags(); } for (String tag : tags) { + // tag is contextPath,so remove first char '/' + tag = tag.substring(1); List byQuery = tagService.findByQuery(tag); if (CollectionUtils.isNotEmpty(byQuery)) { tagsIds.addAll(byQuery.stream().map(TagVO::getId).collect(Collectors.toList())); @@ -76,8 +78,7 @@ public void registerApiDocument(final ApiDocRegisterDTO apiDocRegisterDTO) { apiDTO.setTagIds(tagsIds); apiService.createOrUpdate(apiDTO); } else if (apiDocRegisterDTO.getEventType().equals(EventType.OFFLINE)) { - String contextPath = apiDocRegisterDTO.getContextPath(); - apiService.offlineByContextPath(contextPath); + apiService.offlineByContextPath(apiDocRegisterDTO.getContextPath()); } } From e712d586ee478d9cd991b1e6e2c37151ee4f4627 Mon Sep 17 00:00:00 2001 From: gongzhongqiang Date: Thu, 10 Aug 2023 17:30:28 +0800 Subject: [PATCH 2/4] [ISSUE #4988] Fix swagger doc registered appName use contextPath --- .../manager/impl/PullSwaggerDocServiceImpl.java | 1 - .../manager/impl/RegisterApiDocServiceImpl.java | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/PullSwaggerDocServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/PullSwaggerDocServiceImpl.java index 2ca4e34b3438..6ea2de9f51cf 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/PullSwaggerDocServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/PullSwaggerDocServiceImpl.java @@ -25,7 +25,6 @@ import java.util.Set; import javax.annotation.Resource; -import io.vertx.core.json.Json; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/RegisterApiDocServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/RegisterApiDocServiceImpl.java index 5b7064b491fb..f73be9045bf7 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/RegisterApiDocServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/RegisterApiDocServiceImpl.java @@ -60,16 +60,16 @@ public void registerApiDocument(final ApiDocRegisterDTO apiDocRegisterDTO) { tags = apiDocRegisterDTO.getTags(); } for (String tag : tags) { - // tag is contextPath,so remove first char '/' - tag = tag.substring(1); - List byQuery = tagService.findByQuery(tag); + // tag value is contextPath,so remove first char '/' + String appName = tag.substring(1); + List byQuery = tagService.findByQuery(appName); if (CollectionUtils.isNotEmpty(byQuery)) { tagsIds.addAll(byQuery.stream().map(TagVO::getId).collect(Collectors.toList())); } else { TagDTO tagDTO = new TagDTO(); String id = UUIDUtils.getInstance().generateShortUuid(); - tagDTO.setTagDesc(tag); - tagDTO.setName(tag); + tagDTO.setTagDesc(appName); + tagDTO.setName(appName); tagDTO.setId(id); tagService.createRootTag(tagDTO, null); tagsIds.add(id); From fa73f3471cfa0fcce1c8306091e5bafbaeded866 Mon Sep 17 00:00:00 2001 From: kimmking Date: Wed, 31 Jan 2024 00:19:03 +0800 Subject: [PATCH 3/4] Update PullSwaggerDocServiceImpl.java remove duplicated imports --- .../service/manager/impl/PullSwaggerDocServiceImpl.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/PullSwaggerDocServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/PullSwaggerDocServiceImpl.java index aeaaf755b93a..30ea46de7d97 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/PullSwaggerDocServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/PullSwaggerDocServiceImpl.java @@ -20,12 +20,6 @@ import com.google.common.collect.Interner; import com.google.common.collect.Interners; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.Set; -import javax.annotation.Resource; - import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; From 3c701e3693e9a825cdd4212215bebecba2b36c0d Mon Sep 17 00:00:00 2001 From: kimmking Date: Wed, 31 Jan 2024 00:22:43 +0800 Subject: [PATCH 4/4] Update PullSwaggerDocServiceImpl.java add importing okhttp3.Response --- .../admin/service/manager/impl/PullSwaggerDocServiceImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/PullSwaggerDocServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/PullSwaggerDocServiceImpl.java index 30ea46de7d97..6429795c0847 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/PullSwaggerDocServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/PullSwaggerDocServiceImpl.java @@ -20,6 +20,7 @@ import com.google.common.collect.Interner; import com.google.common.collect.Interners; +import okhttp3.Response; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils;