This is an automated email from the ASF dual-hosted git repository.

xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 327bf65c5 [ISSUE #4848]Storage adjustment for swagger type API 
documents: change from local cache to database. (#4849)
327bf65c5 is described below

commit 327bf65c5c0fe63ae82ea44d25049b085c2e6770
Author: lianjunwei <[email protected]>
AuthorDate: Tue Jul 18 10:52:38 2023 +0800

    [ISSUE #4848]Storage adjustment for swagger type API documents: change from 
local cache to database. (#4849)
    
    * apidoc sql
    
    * refact
    
    * commit
    
    * [Task] Shenyu-admin: Fix API document failed to build because of NPE.
    
    * [Task] Shenyu-admin: Fix API document failed to build because of NPE.
    
    * solve conficts,modify LICENSE.
    
    * delete useless code.
    
    * delete useless code.
    
    * commit
    
    * [ISSUE #3843]admin apidoc fix: the required attribute prompt is incorrect 
when micro service parameter uses "@ApiModelProperty".
    
    * commit
    
    * [shenyu-examples]add swagger to the example project to test the apidoc 
function of the gateway management system.
    
    * commit
    
    * commit
    
    * commit
    
    * [ISSUE #4690]Supports gzip compression in response to HTTP requests.
    
    * [examples]Add Swagger sample project to demonstrate automatic pull 
interface documentation.
    
    * delete exapmple
    
    * delete useless code.
    
    * delete useless code.
    
    * swagger apidoc from local cache to database persistence.
    
    * Storage adjustment for swagger type documents :from local cache to 
database persistence.
    
    * fix get httpMethod
    
    * Fix unit testing.
    
    * Fix unit testing.
    
    * Fix unit testing.
    
    * code style.
    
    * Fix unit testing.
    
    * delete unused imports.
    
    ---------
    
    Co-authored-by: lianjunwei <[email protected]>
    Co-authored-by: dragon-zhang <[email protected]>
    Co-authored-by: xiaoyu <[email protected]>
---
 .../shenyu/admin/controller/ApiDocController.java  |   1 -
 .../apache/shenyu/admin/model/bean/DocInfo.java    |  20 +++
 .../apache/shenyu/admin/model/bean/DocItem.java    |  40 ++---
 .../shenyu/admin/service/manager/DocManager.java   |   8 -
 ...eDocManager.java => PullSwaggerDocService.java} |   4 +-
 ...eDocManager.java => RegisterApiDocService.java} |  19 +--
 .../admin/service/manager/impl/DocManagerImpl.java |  91 ++++++++--
 .../manager/impl/LoadServiceDocEntryImpl.java      |  12 +-
 ...gerImpl.java => PullSwaggerDocServiceImpl.java} |   8 +-
 .../manager/impl/RegisterApiDocServiceImpl.java    | 103 ++++++++++++
 .../service/manager/impl/SwaggerDocParser.java     |   8 +-
 .../AbstractShenyuClientRegisterServiceImpl.java   |  62 +------
 .../admin/controller/ApiDocControllerTest.java     |   1 -
 .../service/manager/impl/DocManagerImplTest.java   |  67 ++------
 .../manager/impl/LoadServiceDocEntryImplTest.java  |   8 +-
 ...mplTest.java => SwaggerDocManagerImplTest.java} |   4 +-
 .../service/manager/impl/SwaggerDocParserTest.java | 186 ++++++++++++++++++---
 ...bstractShenyuClientRegisterServiceImplTest.java |   6 +-
 18 files changed, 430 insertions(+), 218 deletions(-)

diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ApiDocController.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ApiDocController.java
index c0eddecbe..5c2adc5b5 100755
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ApiDocController.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ApiDocController.java
@@ -108,7 +108,6 @@ public class ApiDocController {
                     List<MenuDocItem> docItems = 
docModule.getDocItems().stream()
                         .map(docItem -> {
                             MenuDocItem menuDocItem = new MenuDocItem();
-                            menuDocItem.setId(docItem.getId());
                             menuDocItem.setLabel(docItem.getSummary());
                             menuDocItem.setName(docItem.getName());
                             return menuDocItem;
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/bean/DocInfo.java 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/bean/DocInfo.java
index 10f249160..fafc02d65 100644
--- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/bean/DocInfo.java
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/bean/DocInfo.java
@@ -28,6 +28,8 @@ public class DocInfo {
 
     private String clusterName;
 
+    private String contextPath;
+
     private List<DocModule> docModuleList;
 
     /**
@@ -66,6 +68,24 @@ public class DocInfo {
         this.clusterName = clusterName;
     }
 
+    /**
+     * get contextPath.
+     *
+     * @return contextPath
+     */
+    public String getContextPath() {
+        return contextPath;
+    }
+
+    /**
+     * set contextPath.
+     *
+     * @param contextPath contextPath
+     */
+    public void setContextPath(final String contextPath) {
+        this.contextPath = contextPath;
+    }
+
     /**
      * getDocModuleList.
      *
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/bean/DocItem.java 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/bean/DocItem.java
index a6e69fe51..2f0111d23 100644
--- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/bean/DocItem.java
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/bean/DocItem.java
@@ -27,8 +27,6 @@ import org.apache.commons.lang3.StringUtils;
  */
 public class DocItem {
 
-    private String id;
-
     private String module;
 
     private String name;
@@ -47,6 +45,8 @@ public class DocItem {
      */
     private Collection<String> httpMethodList;
 
+    private Collection<String> consumes;
+
     private Collection<String> produces;
 
     /**
@@ -81,24 +81,6 @@ public class DocItem {
         return multiple || upload;
     }
 
-    /**
-     * getId.
-     *
-     * @return String
-     */
-    public String getId() {
-        return id;
-    }
-
-    /**
-     * setId.
-     *
-     * @param id id
-     */
-    public void setId(final String id) {
-        this.id = id;
-    }
-
     /**
      * getModule.
      *
@@ -207,6 +189,24 @@ public class DocItem {
         this.httpMethodList = httpMethodList;
     }
 
+    /**
+     * get consumes.
+     *
+     * @return consumes
+     */
+    public Collection<String> getConsumes() {
+        return consumes;
+    }
+
+    /**
+     * set consumes.
+     *
+     * @param consumes consumes
+     */
+    public void setConsumes(final Collection<String> consumes) {
+        this.consumes = consumes;
+    }
+
     /**
      * getProduces.
      *
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/DocManager.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/DocManager.java
index a48e9b84a..266190f2a 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/DocManager.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/DocManager.java
@@ -36,14 +36,6 @@ public interface DocManager {
      */
     void addDocInfo(String serviceId, String docJson, Consumer<DocInfo> 
callback);
 
-    /**
-     * get docInfo by title.
-     *
-     * @param title title
-     * @return DocInfo
-     */
-    DocInfo getByTitle(String title);
-
     /**
      * getDocItem.
      *
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/ServiceDocManager.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/PullSwaggerDocService.java
similarity index 93%
copy from 
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/ServiceDocManager.java
copy to 
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/PullSwaggerDocService.java
index d4b5eb68d..b2d8defb0 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/ServiceDocManager.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/PullSwaggerDocService.java
@@ -21,9 +21,9 @@ import java.util.Set;
 import org.apache.shenyu.admin.model.bean.UpstreamInstance;
 
 /**
- * Service document Manager.
+ * pull service api document Manager.
  */
-public interface ServiceDocManager {
+public interface PullSwaggerDocService {
 
     /**
      * pull API document.
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/ServiceDocManager.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/RegisterApiDocService.java
similarity index 68%
rename from 
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/ServiceDocManager.java
rename to 
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/RegisterApiDocService.java
index d4b5eb68d..a23298066 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/ServiceDocManager.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/RegisterApiDocService.java
@@ -17,23 +17,16 @@
 
 package org.apache.shenyu.admin.service.manager;
 
-import java.util.Set;
-import org.apache.shenyu.admin.model.bean.UpstreamInstance;
+import org.apache.shenyu.register.common.dto.ApiDocRegisterDTO;
 
 /**
- * Service document Manager.
+ * register api document manager.
  */
-public interface ServiceDocManager {
+public interface RegisterApiDocService {
 
     /**
-     * pull API document.
-     * @param currentServices currentServices
+     * register api document.
+     * @param apiDocRegisterDTO apiDocRegisterDTO
      */
-    void pullApiDocument(Set<UpstreamInstance> currentServices);
-
-    /**
-     * pull API document.
-     * @param instance instance
-     */
-    void pullApiDocument(UpstreamInstance instance);
+    void registerApiDocument(ApiDocRegisterDTO apiDocRegisterDTO);
 }
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/DocManagerImpl.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/DocManagerImpl.java
index beb8107c1..d2f121537 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/DocManagerImpl.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/DocManagerImpl.java
@@ -19,14 +19,17 @@ package org.apache.shenyu.admin.service.manager.impl;
 
 import java.nio.charset.StandardCharsets;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.Optional;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.function.Consumer;
 
 import com.google.gson.JsonObject;
+import javax.annotation.Resource;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shenyu.admin.model.bean.DocInfo;
@@ -34,7 +37,15 @@ import org.apache.shenyu.admin.model.bean.DocItem;
 import org.apache.shenyu.admin.model.bean.DocModule;
 import org.apache.shenyu.admin.service.manager.DocManager;
 import org.apache.shenyu.admin.service.manager.DocParser;
+import org.apache.shenyu.admin.service.manager.RegisterApiDocService;
+import org.apache.shenyu.common.enums.ApiHttpMethodEnum;
+import org.apache.shenyu.common.enums.ApiSourceEnum;
+import org.apache.shenyu.common.enums.ApiStateEnum;
+import org.apache.shenyu.common.enums.RpcTypeEnum;
 import org.apache.shenyu.common.utils.GsonUtils;
+import org.apache.shenyu.common.utils.JsonUtils;
+import org.apache.shenyu.register.common.dto.ApiDocRegisterDTO;
+import org.apache.shenyu.register.common.enums.EventType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
@@ -47,6 +58,13 @@ import org.springframework.util.DigestUtils;
 public class DocManagerImpl implements DocManager {
     private static final Logger LOG = 
LoggerFactory.getLogger(DocManagerImpl.class);
 
+    private static final String API_DOC_VERSION = "v0.01";
+
+    /**
+     * The constant HTTP.
+     */
+    private static final String HTTP = "http://";;
+
     /**
      * key:title, value:docInfo.
      */
@@ -64,6 +82,9 @@ public class DocManagerImpl implements DocManager {
 
     private static final DocParser SWAGGER_DOC_PARSER = new SwaggerDocParser();
 
+    @Resource
+    private RegisterApiDocService registerApiDocService;
+
     /**
      * add docInfo.
      *
@@ -81,23 +102,67 @@ public class DocManagerImpl implements DocManager {
         if (Objects.equals(newMd5, oldMd5)) {
             return;
         }
-        CLUSTER_MD5_MAP.put(clusterName, newMd5);
+//        CLUSTER_MD5_MAP.put(clusterName, newMd5);
         DocInfo docInfo = getDocInfo(clusterName, docInfoJson);
         if (Objects.isNull(docInfo) || 
CollectionUtils.isEmpty(docInfo.getDocModuleList())) {
             return;
         }
         List<DocModule> docModules = docInfo.getDocModuleList();
         DOC_DEFINITION_MAP.put(docInfo.getTitle(), docInfo);
-        docModules.forEach(docModule -> 
docModule.getDocItems().forEach(docItem -> ITEM_DOC_MAP.put(docItem.getId(), 
docItem)));
+        docModules.forEach(docModule -> 
docModule.getDocItems().forEach(docItem -> {
+            ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
+                .consume(this.getProduceConsume(docItem.getConsumes()))
+                .produce(this.getProduceConsume(docItem.getProduces()))
+                .httpMethod(this.getHttpMethod(docItem))
+                .contextPath(docInfo.getContextPath())
+                .ext(this.buildExtJson(docInfo, docItem))
+                .document(JsonUtils.toJson(docItem))
+                .rpcType(RpcTypeEnum.HTTP.getName())
+                .version(API_DOC_VERSION)
+                .apiDesc(docItem.getDescription())
+                .tags(Collections.singletonList(docInfo.getContextPath()))
+                .apiPath(docItem.getName())
+                .apiSource(ApiSourceEnum.SWAGGER.getValue())
+                .state(ApiStateEnum.PUBLISHED.getState())
+                .apiOwner("admin")
+                .eventType(EventType.REGISTER)
+                .build();
+
+            registerApiDocService.registerApiDocument(build);
+        }));
+
         callback.accept(docInfo);
     }
 
+    private String getProduceConsume(final Collection<String> list) {
+        String res = StringUtils.EMPTY;
+        if (Objects.nonNull(list)) {
+            Optional<String> first = list.stream().findFirst();
+            if (first.isPresent()) {
+                res = first.get();
+            }
+        }
+        return StringUtils.isNotEmpty(res) ? res : "*/*";
+    }
+
+    private Integer getHttpMethod(final DocItem docItem) {
+        Integer httpMethod = null;
+        Optional<String> first = 
docItem.getHttpMethodList().stream().findFirst();
+        if (first.isPresent()) {
+            String method = docItem.getHttpMethodList().size() == 1 ? 
StringUtils.upperCase(first.get()) : ApiHttpMethodEnum.GET.getName();
+            httpMethod = ApiHttpMethodEnum.getValueByName(method);
+        }
+        return httpMethod;
+    }
+
     private DocInfo getDocInfo(final String clusterName, final String 
docInfoJson) {
         try {
             JsonObject docRoot = GsonUtils.getInstance().fromJson(docInfoJson, 
JsonObject.class);
-            docRoot.addProperty("basePath", "/" + clusterName);
+            String contexPath = "/" + clusterName;
+            docRoot.addProperty("basePath", contexPath);
             DocInfo docInfo = SWAGGER_DOC_PARSER.parseJson(docRoot);
             docInfo.setClusterName(clusterName);
+            docInfo.setContextPath(contexPath);
             return docInfo;
         } catch (Exception e) {
             LOG.error("getDocInfo error= ", e);
@@ -105,15 +170,17 @@ public class DocManagerImpl implements DocManager {
         }
     }
 
-    /**
-     * get doc By Title.
-     *
-     * @param title title
-     * @return DocInfo
-     */
-    @Override
-    public DocInfo getByTitle(final String title) {
-        return DOC_DEFINITION_MAP.get(title);
+    private String buildExtJson(final DocInfo docInfo, final DocItem docItem) {
+        ApiDocRegisterDTO.ApiExt ext = new ApiDocRegisterDTO.ApiExt();
+        ext.setHost("host");
+        ext.setPort(null);
+        ext.setServiceName(docInfo.getClusterName());
+        ext.setMethodName(docItem.getName());
+        ext.setParameterTypes("");
+        ext.setRpcExt(null);
+        ext.setAddPrefixed(false);
+        ext.setProtocol(HTTP);
+        return GsonUtils.getInstance().toJson(ext);
     }
 
     /**
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/LoadServiceDocEntryImpl.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/LoadServiceDocEntryImpl.java
index 103ab6067..6b6971918 100755
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/LoadServiceDocEntryImpl.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/LoadServiceDocEntryImpl.java
@@ -41,7 +41,7 @@ import org.apache.shenyu.admin.service.SelectorService;
 import org.apache.shenyu.admin.service.ShenyuDictService;
 import org.apache.shenyu.admin.service.converter.SelectorHandleConverterFactor;
 import org.apache.shenyu.admin.service.manager.LoadServiceDocEntry;
-import org.apache.shenyu.admin.service.manager.ServiceDocManager;
+import org.apache.shenyu.admin.service.manager.PullSwaggerDocService;
 import org.apache.shenyu.common.constant.AdminConstants;
 import org.apache.shenyu.common.dto.SelectorData;
 import org.apache.shenyu.common.dto.convert.selector.CommonUpstream;
@@ -69,19 +69,19 @@ public class LoadServiceDocEntryImpl implements 
LoadServiceDocEntry {
 
     private final PluginMapper pluginMapper;
 
-    private final ServiceDocManager serviceDocManager;
+    private final PullSwaggerDocService pullSwaggerDocService;
 
     private final ShenyuDictService shenyuDictService;
 
     public LoadServiceDocEntryImpl(final SelectorService selectorService,
                                    final SelectorHandleConverterFactor 
converterFactor,
                                    final PluginMapper pluginMapper,
-                                   final ServiceDocManager serviceDocManager,
+                                   final PullSwaggerDocService 
pullSwaggerDocService,
                                    final ShenyuDictService shenyuDictService) {
         this.selectorService = selectorService;
         this.converterFactor = converterFactor;
         this.pluginMapper = pluginMapper;
-        this.serviceDocManager = serviceDocManager;
+        this.pullSwaggerDocService = pullSwaggerDocService;
         this.shenyuDictService = shenyuDictService;
     }
 
@@ -97,7 +97,7 @@ public class LoadServiceDocEntryImpl implements 
LoadServiceDocEntry {
         }
         final Set<UpstreamInstance> currentServices = new 
HashSet<>(serviceList);
         LOG.info("load api document  serviceList={}", 
JsonUtils.toJson(currentServices));
-        serviceDocManager.pullApiDocument(currentServices);
+        pullSwaggerDocService.pullApiDocument(currentServices);
     }
 
     @Override
@@ -113,7 +113,7 @@ public class LoadServiceDocEntryImpl implements 
LoadServiceDocEntry {
             }
             final Set<UpstreamInstance> currentServices = new 
HashSet<>(serviceList);
             LOG.info("loadDocOnSelectorChanged serviceList={}", 
JsonUtils.toJson(currentServices));
-            serviceDocManager.pullApiDocument(currentServices);
+            pullSwaggerDocService.pullApiDocument(currentServices);
         }
     }
 
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/ServiceDocManagerImpl.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/PullSwaggerDocServiceImpl.java
similarity index 92%
rename from 
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/ServiceDocManagerImpl.java
rename to 
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/PullSwaggerDocServiceImpl.java
index 9bcc09f0a..cd4383ba2 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/ServiceDocManagerImpl.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/PullSwaggerDocServiceImpl.java
@@ -25,7 +25,7 @@ import java.util.Set;
 import javax.annotation.Resource;
 import org.apache.shenyu.admin.model.bean.UpstreamInstance;
 import org.apache.shenyu.admin.service.manager.DocManager;
-import org.apache.shenyu.admin.service.manager.ServiceDocManager;
+import org.apache.shenyu.admin.service.manager.PullSwaggerDocService;
 import org.apache.shenyu.admin.utils.HttpUtils;
 import org.apache.shenyu.common.utils.JsonUtils;
 import org.slf4j.Logger;
@@ -36,8 +36,8 @@ import org.springframework.stereotype.Service;
  * ServiceDocManagerImpl.
  */
 @Service
-public class ServiceDocManagerImpl implements ServiceDocManager {
-    private static final Logger LOG = 
LoggerFactory.getLogger(ServiceDocManagerImpl.class);
+public class PullSwaggerDocServiceImpl implements PullSwaggerDocService {
+    private static final Logger LOG = 
LoggerFactory.getLogger(PullSwaggerDocServiceImpl.class);
 
     private static final HttpUtils HTTP_UTILS = new HttpUtils();
 
@@ -72,7 +72,7 @@ public class ServiceDocManagerImpl implements 
ServiceDocManager {
             docManager.addDocInfo(
                 clusterName,
                 body,
-                callback -> LOG.info("load api document 
successful,clusterName={}, iPandPort={}",
+                callback -> LOG.info("load api document 
successful,clusterName={}, ipPort={}",
                     clusterName, instance.getIp() + ":" + instance.getPort())
             );
             CLUSTER_LASTSTARTUPTIME_MAP.put(clusterName, 
instance.getStartupTime());
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
new file mode 100644
index 000000000..334a04a7e
--- /dev/null
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/RegisterApiDocServiceImpl.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.admin.service.manager.impl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+import javax.annotation.Resource;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.shenyu.admin.model.dto.ApiDTO;
+import org.apache.shenyu.admin.model.dto.TagDTO;
+import org.apache.shenyu.admin.model.vo.TagVO;
+import org.apache.shenyu.admin.service.ApiService;
+import org.apache.shenyu.admin.service.TagService;
+import org.apache.shenyu.admin.service.manager.RegisterApiDocService;
+import org.apache.shenyu.common.constant.AdminConstants;
+import org.apache.shenyu.common.utils.UUIDUtils;
+import org.apache.shenyu.register.common.dto.ApiDocRegisterDTO;
+import org.apache.shenyu.register.common.enums.EventType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+/**
+ * Implementation of the {@link 
org.apache.shenyu.admin.service.manager.RegisterApiDocService}.
+ */
+@Service
+public class RegisterApiDocServiceImpl implements RegisterApiDocService {
+    private static final Logger LOG = 
LoggerFactory.getLogger(RegisterApiDocServiceImpl.class);
+
+    @Resource
+    private ApiService apiService;
+
+    @Resource
+    private TagService tagService;
+
+    @Override
+    public void registerApiDocument(final ApiDocRegisterDTO apiDocRegisterDTO) 
{
+        if (apiDocRegisterDTO.getEventType().equals(EventType.REGISTER)) {
+            ApiDTO apiDTO = buildApiDTO(apiDocRegisterDTO);
+            apiService.deleteByApiPathHttpMethodRpcType(apiDTO.getApiPath(), 
apiDTO.getHttpMethod(), apiDTO.getRpcType());
+            List<String> tagsIds = new ArrayList<>();
+            List<String> tags = 
Collections.singletonList(apiDocRegisterDTO.getContextPath());
+            if (CollectionUtils.isNotEmpty(apiDocRegisterDTO.getTags())) {
+                tags = apiDocRegisterDTO.getTags();
+            }
+            for (String tag : tags) {
+                List<TagVO> byQuery = tagService.findByQuery(tag);
+                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.setParentTagId(AdminConstants.TAG_ROOT_PARENT_ID);
+                    tagDTO.setId(id);
+                    tagService.create(tagDTO);
+                    tagsIds.add(id);
+                }
+            }
+            apiDTO.setTagIds(tagsIds);
+            apiService.createOrUpdate(apiDTO);
+        } else if (apiDocRegisterDTO.getEventType().equals(EventType.OFFLINE)) 
{
+            String contextPath = apiDocRegisterDTO.getContextPath();
+            apiService.offlineByContextPath(contextPath);
+        }
+    }
+
+    private ApiDTO buildApiDTO(final ApiDocRegisterDTO apiDocRegisterDTO) {
+        ApiDTO apiDTO = new ApiDTO();
+        apiDTO.setApiPath(apiDocRegisterDTO.getApiPath());
+        apiDTO.setApiSource(apiDocRegisterDTO.getApiSource());
+        apiDTO.setApiOwner(apiDocRegisterDTO.getApiOwner());
+        apiDTO.setDocument(apiDocRegisterDTO.getDocument());
+        apiDTO.setExt(apiDocRegisterDTO.getExt());
+        apiDTO.setVersion(apiDocRegisterDTO.getVersion());
+        apiDTO.setRpcType(apiDocRegisterDTO.getRpcType());
+        apiDTO.setConsume(apiDocRegisterDTO.getConsume());
+        apiDTO.setProduce(apiDocRegisterDTO.getProduce());
+        apiDTO.setContextPath(apiDocRegisterDTO.getContextPath());
+        apiDTO.setHttpMethod(apiDocRegisterDTO.getHttpMethod());
+        apiDTO.setState(apiDocRegisterDTO.getState());
+        apiDTO.setApiDesc(apiDocRegisterDTO.getApiDesc());
+        return apiDTO;
+    }
+}
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/SwaggerDocParser.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/SwaggerDocParser.java
index 953d823d5..03175efc4 100755
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/SwaggerDocParser.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/SwaggerDocParser.java
@@ -28,12 +28,12 @@ import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
 import java.util.Set;
-import java.util.UUID;
 import java.util.stream.Collectors;
 
 import com.google.gson.JsonArray;
 import com.google.gson.JsonObject;
 import com.google.gson.reflect.TypeToken;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.math.NumberUtils;
 import org.apache.shenyu.admin.model.bean.CustomCode;
 import org.apache.shenyu.admin.model.bean.DocInfo;
@@ -43,7 +43,6 @@ import org.apache.shenyu.admin.model.bean.DocParameter;
 import org.apache.shenyu.admin.service.manager.DocParser;
 import org.apache.shenyu.common.utils.GsonUtils;
 import org.springframework.beans.BeanUtils;
-import org.springframework.util.CollectionUtils;
 
 /**
  * Parse the JSON content of swagger.
@@ -69,7 +68,6 @@ public class SwaggerDocParser implements DocParser {
         Set<String> pathNameSet = paths.keySet();
         for (String apiPath : pathNameSet) {
             JsonObject pathInfo = paths.getAsJsonObject(apiPath);
-            // key: get,post,head...
             Collection<String> httpMethodList = getHttpMethods(pathInfo);
             Optional<String> first = httpMethodList.stream().findFirst();
             if (first.isPresent()) {
@@ -123,7 +121,6 @@ public class SwaggerDocParser implements DocParser {
     }
 
     protected Collection<String> getHttpMethods(final JsonObject pathInfo) {
-        // key: get,post,head...
         Set<String> httpMethodList = pathInfo.keySet();
         List<String> retList = new ArrayList<>(httpMethodList);
         Collections.sort(retList);
@@ -136,7 +133,6 @@ public class SwaggerDocParser implements DocParser {
         apiName = basePath + apiName;
 
         DocItem docItem = new DocItem();
-        docItem.setId(UUID.randomUUID().toString());
         docItem.setName(apiName);
         if (Objects.nonNull(docInfo.get("summary"))) {
             docItem.setSummary(docInfo.get("summary").getAsString());
@@ -144,6 +140,8 @@ public class SwaggerDocParser implements DocParser {
         if (Objects.nonNull(docInfo.get("description"))) {
             docItem.setDescription(docInfo.get("description").getAsString());
         }
+        
docItem.setConsumes(GsonUtils.getGson().fromJson(docInfo.getAsJsonArray("consumes"),
 new TypeToken<List<String>>() {
+        }.getType()));
         
docItem.setProduces(GsonUtils.getGson().fromJson(docInfo.getAsJsonArray("produces"),
 new TypeToken<List<String>>() {
         }.getType()));
 
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java
index 6c391e5db..8fd025f75 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java
@@ -20,18 +20,14 @@ package org.apache.shenyu.admin.service.register;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shenyu.admin.listener.DataChangedEvent;
-import org.apache.shenyu.admin.model.dto.ApiDTO;
 import org.apache.shenyu.admin.model.dto.RuleConditionDTO;
 import org.apache.shenyu.admin.model.dto.RuleDTO;
-import org.apache.shenyu.admin.model.dto.TagDTO;
 import org.apache.shenyu.admin.model.entity.SelectorDO;
-import org.apache.shenyu.admin.model.vo.TagVO;
-import org.apache.shenyu.admin.service.ApiService;
 import org.apache.shenyu.admin.service.MetaDataService;
 import org.apache.shenyu.admin.service.RuleService;
 import org.apache.shenyu.admin.service.SelectorService;
-import org.apache.shenyu.admin.service.TagService;
 import org.apache.shenyu.admin.service.impl.UpstreamCheckService;
+import org.apache.shenyu.admin.service.manager.RegisterApiDocService;
 import org.apache.shenyu.admin.utils.CommonUpstreamUtils;
 import org.apache.shenyu.admin.utils.ShenyuResultMessage;
 import org.apache.shenyu.common.constant.AdminConstants;
@@ -45,15 +41,12 @@ import org.apache.shenyu.common.enums.ParamTypeEnum;
 import org.apache.shenyu.common.exception.ShenyuException;
 import org.apache.shenyu.common.utils.PathUtils;
 import org.apache.shenyu.common.utils.PluginNameAdapter;
-import org.apache.shenyu.common.utils.UUIDUtils;
 import org.apache.shenyu.register.common.dto.ApiDocRegisterDTO;
 import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO;
 import org.apache.shenyu.register.common.dto.URIRegisterDTO;
-import org.apache.shenyu.register.common.enums.EventType;
 import org.springframework.context.ApplicationEventPublisher;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
@@ -89,10 +82,7 @@ public abstract class 
AbstractShenyuClientRegisterServiceImpl extends FallbackSh
     private UpstreamCheckService upstreamCheckService;
 
     @Resource
-    private ApiService apiService;
-
-    @Resource
-    private TagService tagService;
+    private RegisterApiDocService registerApiDocService;
 
     /**
      * Selector handler string.
@@ -152,56 +142,10 @@ public abstract class 
AbstractShenyuClientRegisterServiceImpl extends FallbackSh
 
     @Override
     public String registerApiDoc(final ApiDocRegisterDTO apiDocRegisterDTO) {
-        if (apiDocRegisterDTO.getEventType().equals(EventType.REGISTER)) {
-            ApiDTO apiDTO = buildApiDTO(apiDocRegisterDTO);
-            apiService.deleteByApiPathHttpMethodRpcType(apiDTO.getApiPath(), 
apiDTO.getHttpMethod(), apiDTO.getRpcType());
-            List<String> tagsIds = new ArrayList<>();
-            List<String> tags = 
Collections.singletonList(apiDocRegisterDTO.getContextPath());
-            if (CollectionUtils.isNotEmpty(apiDocRegisterDTO.getTags())) {
-                tags = apiDocRegisterDTO.getTags();
-            }
-            for (String tag : tags) {
-                List<TagVO> byQuery = tagService.findByQuery(tag);
-                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.setParentTagId(AdminConstants.TAG_ROOT_PARENT_ID);
-                    tagDTO.setId(id);
-                    tagService.create(tagDTO);
-                    tagsIds.add(id);
-                }
-            }
-            apiDTO.setTagIds(tagsIds);
-            apiService.createOrUpdate(apiDTO);
-        } else if (apiDocRegisterDTO.getEventType().equals(EventType.OFFLINE)) 
{
-            String contextPath = apiDocRegisterDTO.getContextPath();
-            apiService.offlineByContextPath(contextPath);
-        }
+        registerApiDocService.registerApiDocument(apiDocRegisterDTO);
         return ShenyuResultMessage.SUCCESS;
     }
 
-    private ApiDTO buildApiDTO(final ApiDocRegisterDTO apiDocRegisterDTO) {
-        ApiDTO apiDTO = new ApiDTO();
-        apiDTO.setApiPath(apiDocRegisterDTO.getApiPath());
-        apiDTO.setApiSource(apiDocRegisterDTO.getApiSource());
-        apiDTO.setApiOwner(apiDocRegisterDTO.getApiOwner());
-        apiDTO.setDocument(apiDocRegisterDTO.getDocument());
-        apiDTO.setExt(apiDocRegisterDTO.getExt());
-        apiDTO.setVersion(apiDocRegisterDTO.getVersion());
-        apiDTO.setRpcType(apiDocRegisterDTO.getRpcType());
-        apiDTO.setConsume(apiDocRegisterDTO.getConsume());
-        apiDTO.setProduce(apiDocRegisterDTO.getProduce());
-        apiDTO.setContextPath(apiDocRegisterDTO.getContextPath());
-        apiDTO.setHttpMethod(apiDocRegisterDTO.getHttpMethod());
-        apiDTO.setState(apiDocRegisterDTO.getState());
-        apiDTO.setApiDesc(apiDocRegisterDTO.getApiDesc());
-        return apiDTO;
-    }
-
     /**
      * Register uri string.
      *
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/ApiDocControllerTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/ApiDocControllerTest.java
index f3f096383..937ef3e44 100644
--- 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/ApiDocControllerTest.java
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/ApiDocControllerTest.java
@@ -80,7 +80,6 @@ public class ApiDocControllerTest {
     @Test
     public void testGetDocItem() throws Exception {
         DocItem docItem = new DocItem();
-        docItem.setId("123");
         docItem.setApiOrder(1);
         docItem.setDescription("this is a test");
         given(this.docManager.getDocItem("123")).willReturn(docItem);
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/impl/DocManagerImplTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/impl/DocManagerImplTest.java
index f8311779a..b351288c4 100644
--- 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/impl/DocManagerImplTest.java
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/impl/DocManagerImplTest.java
@@ -19,9 +19,11 @@ package org.apache.shenyu.admin.service.manager.impl;
 
 import org.apache.shenyu.admin.model.bean.DocInfo;
 import org.apache.shenyu.admin.model.bean.DocItem;
+import org.apache.shenyu.admin.service.manager.RegisterApiDocService;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.InjectMocks;
+import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.mockito.junit.jupiter.MockitoSettings;
 import org.mockito.quality.Strictness;
@@ -46,68 +48,20 @@ public class DocManagerImplTest {
     @InjectMocks
     private DocManagerImpl docManager;
 
+    @Mock
+    private RegisterApiDocService registerApiDocService;
+
     @Test
     public void testAddDocInfo() {
         String clusterName = "testClusterName";
         AtomicBoolean atomicBoolean = new AtomicBoolean(false);
-        String docInfoJson = "{\n"
-                + "    \"info\":\n"
-                + "    {\n"
-                + "        \"title\":\"testTitle\"\n"
-                + "    },\n"
-                + "    \"paths\":\n"
-                + "    {\n"
-                + "        \"testPath1\":\n"
-                + "        {\n"
-                + "            \"post\":\n"
-                + "            {\n"
-                + "                \"summary\":\"testSummary\",\n"
-                + "                \"description\":\"testDescription\",\n"
-                + "                \"produces\": [\"application/json\", 
\"application/xml\"],\n"
-                + "                \"multiple\":\"true\",\n"
-                + "                \"module_order\":1,\n"
-                + "                \"api_order\":1\n"
-                + "            }\n"
-                + "        }\n"
-                + "    }\n"
-                + "}";
-
-        docManager.addDocInfo(clusterName, docInfoJson, docInfo -> 
atomicBoolean.set(true));
+        docManager.addDocInfo(clusterName, SwaggerDocParserTest.DOC_INFO_JSON, 
docInfo -> {
+            assertEquals(docInfo.getTitle(), "shenyu-examples-http-swagger2 
API");
+            assertEquals(docInfo.getClusterName(), "testClusterName");
+            atomicBoolean.set(true);
+        });
 
         assertTrue(atomicBoolean.get());
-
-        Class<DocManagerImpl> docManageClass = DocManagerImpl.class;
-        Map<String, DocInfo> docDefinitionMap;
-        try {
-            Field field = 
docManageClass.getDeclaredField("DOC_DEFINITION_MAP");
-            field.setAccessible(true);
-            docDefinitionMap = (Map<String, DocInfo>) field.get(null);
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
-        DocInfo docInfo = docDefinitionMap.get("testTitle");
-        assertEquals(docInfo.getClusterName(), "testClusterName");
-        assertEquals(docInfo.getTitle(), "testTitle");
-        assertEquals(docManager.getByTitle("testTitle").getClusterName(), 
"testClusterName");
-    }
-
-    @Test
-    public void testGetByTitle() {
-        Class<DocManagerImpl> docManageClass = DocManagerImpl.class;
-        Map<String, DocInfo> docDefinitionMap;
-        try {
-            Field field = 
docManageClass.getDeclaredField("DOC_DEFINITION_MAP");
-            field.setAccessible(true);
-            docDefinitionMap = (Map<String, DocInfo>) field.get(null);
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
-        DocManagerImpl docManager = new DocManagerImpl();
-        String title = "testTitle";
-        DocInfo expectedDocInfo = new DocInfo();
-        expectedDocInfo.setTitle("testTitle");
-        docDefinitionMap.put("testTitle", expectedDocInfo);
-        assertEquals(expectedDocInfo, docManager.getByTitle(title));
     }
 
     @Test
@@ -123,7 +77,6 @@ public class DocManagerImplTest {
         }
         String id = "1";
         DocItem expectedDocItem = new DocItem();
-        expectedDocItem.setId(id);
         itemDocMap.put(id, expectedDocItem);
         assertEquals(expectedDocItem, docManager.getDocItem(id));
     }
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/impl/LoadServiceDocEntryImplTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/impl/LoadServiceDocEntryImplTest.java
index a4d4745c9..2d6fbd2d0 100644
--- 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/impl/LoadServiceDocEntryImplTest.java
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/impl/LoadServiceDocEntryImplTest.java
@@ -28,7 +28,7 @@ import org.apache.shenyu.admin.service.SelectorService;
 import org.apache.shenyu.admin.service.ShenyuDictService;
 import org.apache.shenyu.admin.service.converter.SelectorHandleConverter;
 import org.apache.shenyu.admin.service.converter.SelectorHandleConverterFactor;
-import org.apache.shenyu.admin.service.manager.ServiceDocManager;
+import org.apache.shenyu.admin.service.manager.PullSwaggerDocService;
 import org.apache.shenyu.common.dto.SelectorData;
 import org.apache.shenyu.common.dto.convert.selector.CommonUpstream;
 import org.apache.shenyu.common.enums.DataEventTypeEnum;
@@ -69,7 +69,7 @@ public class LoadServiceDocEntryImplTest {
     private PluginMapper pluginMapper;
 
     @Mock
-    private ServiceDocManager serviceDocManager;
+    private PullSwaggerDocService pullSwaggerDocService;
 
     @Mock
     private ShenyuDictService shenyuDictService;
@@ -126,7 +126,7 @@ public class LoadServiceDocEntryImplTest {
         when(selectorService.listByPage(any())).thenReturn(commonPager);
         when(pluginMapper.selectByNames(any())).thenReturn(pluginDOList);
         loadServiceDocEntry.loadApiDocument();
-        verify(serviceDocManager).pullApiDocument((Set<UpstreamInstance>) 
any());
+        verify(pullSwaggerDocService).pullApiDocument((Set<UpstreamInstance>) 
any());
     }
 
     @Test
@@ -144,6 +144,6 @@ public class LoadServiceDocEntryImplTest {
         this.testLoadApiDocument();
         when(shenyuDictService.findByDictCodeName(any(), 
any())).thenReturn(null);
         loadServiceDocEntry.loadDocOnSelectorChanged(changedList, eventType);
-        verify(serviceDocManager).pullApiDocument((Set<UpstreamInstance>) 
any());
+        verify(pullSwaggerDocService).pullApiDocument((Set<UpstreamInstance>) 
any());
     }
 }
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/impl/ServiceDocManagerImplTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/impl/SwaggerDocManagerImplTest.java
similarity index 94%
rename from 
shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/impl/ServiceDocManagerImplTest.java
rename to 
shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/impl/SwaggerDocManagerImplTest.java
index 03bbde9ef..aa247083b 100644
--- 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/impl/ServiceDocManagerImplTest.java
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/impl/SwaggerDocManagerImplTest.java
@@ -33,10 +33,10 @@ import static org.mockito.Mockito.verify;
 
 @ExtendWith(MockitoExtension.class)
 @MockitoSettings(strictness = Strictness.LENIENT)
-public class ServiceDocManagerImplTest {
+public class SwaggerDocManagerImplTest {
 
     @InjectMocks
-    private ServiceDocManagerImpl serviceDocManager;
+    private PullSwaggerDocServiceImpl serviceDocManager;
 
     @Mock
     private Set<UpstreamInstance> currentServices;
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/impl/SwaggerDocParserTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/impl/SwaggerDocParserTest.java
index 5e7cdc050..acc32c604 100644
--- 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/impl/SwaggerDocParserTest.java
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/manager/impl/SwaggerDocParserTest.java
@@ -31,35 +31,175 @@ import org.mockito.quality.Strictness;
 @MockitoSettings(strictness = Strictness.LENIENT)
 public class SwaggerDocParserTest {
 
+    public static final String DOC_INFO_JSON = "{\n"
+        + "    \"swagger\":\"2.0\",\n"
+        + "    \"info\":{\n"
+        + "        \"description\":\"shenyu-examples-http-swagger2 API\",\n"
+        + "        \"version\":\"2.3.0\",\n"
+        + "        \"title\":\"shenyu-examples-http-swagger2 API\",\n"
+        + "        \"contact\":{\n"
+        + "            \"name\":\"ShenYu\",\n"
+        + "            \"url\":\"https://github.com/apache/shenyu\",\n";
+        + "            \"email\":\"[email protected]\"\n"
+        + "        }\n"
+        + "    },\n"
+        + "    \"host\":\"127.0.0.1:8190\",\n"
+        + "    \"basePath\":\"/\",\n"
+        + "    \"tags\":[\n"
+        + "        {\n"
+        + "            \"name\":\"Order API\",\n"
+        + "            \"description\":\"Order Controller\"\n"
+        + "        },\n"
+        + "        {\n"
+        + "            \"name\":\"http-test-controller\",\n"
+        + "            \"description\":\"Http Test Controller\"\n"
+        + "        }\n"
+        + "    ],\n"
+        + "    \"paths\":{\n"
+        + "        \"/order/path/{id}/{name}\":{\n"
+        + "            \"get\":{\n"
+        + "                \"tags\":[\n"
+        + "                    \"Order API\"\n"
+        + "                ],\n"
+        + "                \"summary\":\"getPathVariable\",\n"
+        + "                \"description\":\"get path variable.\",\n"
+        + "                \"operationId\":\"getPathVariableUsingGET_1\",\n"
+        + "                \"produces\":[\n"
+        + "                    \"*/*\"\n"
+        + "                ],\n"
+        + "                \"parameters\":[\n"
+        + "                    {\n"
+        + "                        \"name\":\"X-Access-Token\",\n"
+        + "                        \"in\":\"header\",\n"
+        + "                        \"description\":\"user auth\",\n"
+        + "                        \"required\":false,\n"
+        + "                        \"type\":\"string\"\n"
+        + "                    },\n"
+        + "                    {\n"
+        + "                        \"name\":\"id\",\n"
+        + "                        \"in\":\"path\",\n"
+        + "                        \"description\":\"id\",\n"
+        + "                        \"required\":true,\n"
+        + "                        \"type\":\"string\"\n"
+        + "                    },\n"
+        + "                    {\n"
+        + "                        \"name\":\"name\",\n"
+        + "                        \"in\":\"path\",\n"
+        + "                        \"description\":\"name\",\n"
+        + "                        \"required\":true,\n"
+        + "                        \"type\":\"string\"\n"
+        + "                    }\n"
+        + "                ],\n"
+        + "                \"responses\":{\n"
+        + "                    \"200\":{\n"
+        + "                        \"description\":\"OK\",\n"
+        + "                        \"schema\":{\n"
+        + "                            \"$ref\":\"#/definitions/OrderDTO\"\n"
+        + "                        }\n"
+        + "                    },\n"
+        + "                \"deprecated\":false\n"
+        + "            }\n"
+        + "        },\n"
+        + "        \"/test/payment\":{\n"
+        + "            \"post\":{\n"
+        + "                \"tags\":[\n"
+        + "                    \"http-test-controller\"\n"
+        + "                ],\n"
+        + "                \"summary\":\"payment\",\n"
+        + "                \"description\":\"The user pays the order.\",\n"
+        + "                \"operationId\":\"postUsingPOST\",\n"
+        + "                \"consumes\":[\n"
+        + "                    \"application/json\"\n"
+        + "                ],\n"
+        + "                \"produces\":[\n"
+        + "                    \"*/*\"\n"
+        + "                ],\n"
+        + "                \"parameters\":[\n"
+        + "                    {\n"
+        + "                        \"name\":\"X-Access-Token\",\n"
+        + "                        \"in\":\"header\",\n"
+        + "                        \"description\":\"user auth\",\n"
+        + "                        \"required\":false,\n"
+        + "                        \"type\":\"string\"\n"
+        + "                    },\n"
+        + "                    {\n"
+        + "                        \"in\":\"body\",\n"
+        + "                        \"name\":\"userDTO\",\n"
+        + "                        \"description\":\"userDTO\",\n"
+        + "                        \"required\":true,\n"
+        + "                        \"schema\":{\n"
+        + "                            \"$ref\":\"#/definitions/UserDTO\"\n"
+        + "                        }\n"
+        + "                    }\n"
+        + "                ],\n"
+        + "                \"responses\":{\n"
+        + "                    \"200\":{\n"
+        + "                        \"description\":\"OK\",\n"
+        + "                        \"schema\":{\n"
+        + "                            \"$ref\":\"#/definitions/UserDTO\"\n"
+        + "                        }\n"
+        + "                    }\n"
+        + "                },\n"
+        + "                \"deprecated\":false\n"
+        + "            }\n"
+        + "          }\n"
+        + "        }\n"
+        + "    },\n"
+        + "    \"definitions\":{\n"
+        + "        \"Mono«string»\":{\n"
+        + "            \"type\":\"object\",\n"
+        + "            \"title\":\"Mono«string»\"\n"
+        + "        },\n"
+        + "        \"OrderDTO\":{\n"
+        + "            \"type\":\"object\",\n"
+        + "            \"required\":[\n"
+        + "                \"id\",\n"
+        + "                \"name\"\n"
+        + "            ],\n"
+        + "            \"properties\":{\n"
+        + "                \"id\":{\n"
+        + "                    \"type\":\"string\",\n"
+        + "                    \"example\":100000,\n"
+        + "                    \"description\":\"id\"\n"
+        + "                },\n"
+        + "                \"name\":{\n"
+        + "                    \"type\":\"string\",\n"
+        + "                    \"example\":\"jack\",\n"
+        + "                    \"description\":\"name\"\n"
+        + "                }\n"
+        + "            },\n"
+        + "            \"title\":\"OrderDTO\"\n"
+        + "        },\n"
+        + "        \"UserDTO\":{\n"
+        + "            \"type\":\"object\",\n"
+        + "            \"required\":[\n"
+        + "                \"userId\"\n"
+        + "            ],\n"
+        + "            \"properties\":{\n"
+        + "                \"userId\":{\n"
+        + "                    \"type\":\"string\",\n"
+        + "                    \"example\":100000,\n"
+        + "                    \"description\":\"user id\"\n"
+        + "                },\n"
+        + "                \"userName\":{\n"
+        + "                    \"type\":\"string\",\n"
+        + "                    \"example\":\"shenyu\",\n"
+        + "                    \"description\":\"user name\"\n"
+        + "                }\n"
+        + "            },\n"
+        + "            \"title\":\"UserDTO\"\n"
+        + "        }\n"
+        + "    }\n"
+        + "}";
+
     @InjectMocks
     private SwaggerDocParser swaggerDocParser;
 
     @Test
     public void testParseJson() {
-        String docInfoJson = "{\n"
-                + "    \"info\":\n"
-                + "    {\n"
-                + "        \"title\":\"testTitle\"\n"
-                + "    },\n"
-                + "    \"paths\":\n"
-                + "    {\n"
-                + "        \"testPath1\":\n"
-                + "        {\n"
-                + "            \"post\":\n"
-                + "            {\n"
-                + "                \"summary\":\"testSummary\",\n"
-                + "                \"description\":\"testDescription\",\n"
-                + "                \"produces\": [\"application/json\", 
\"application/xml\"],\n"
-                + "                \"multiple\":\"true\",\n"
-                + "                \"module_order\":1,\n"
-                + "                \"api_order\":1\n"
-                + "            }\n"
-                + "        }\n"
-                + "    }\n"
-                + "}";
-        JsonObject docRoot = GsonUtils.getInstance().fromJson(docInfoJson, 
JsonObject.class);
+        JsonObject docRoot = GsonUtils.getInstance().fromJson(DOC_INFO_JSON, 
JsonObject.class);
         docRoot.addProperty("basePath", "/" + "testClusterName");
         DocInfo docInfo = swaggerDocParser.parseJson(docRoot);
-        assert 
docInfo.getDocModuleList().get(0).getModule().equals("testTitle");
+        assert 
docInfo.getDocModuleList().get(0).getModule().equals("shenyu-examples-http-swagger2
 API");
     }
 }
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImplTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImplTest.java
index d6b33ab8a..9239a3294 100644
--- 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImplTest.java
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImplTest.java
@@ -27,6 +27,7 @@ import org.apache.shenyu.admin.service.ApiService;
 import org.apache.shenyu.admin.service.TagService;
 import org.apache.shenyu.admin.service.MetaDataService;
 import org.apache.shenyu.admin.service.impl.UpstreamCheckService;
+import org.apache.shenyu.admin.service.manager.RegisterApiDocService;
 import org.apache.shenyu.admin.utils.ShenyuResultMessage;
 import org.apache.shenyu.common.dto.SelectorData;
 import org.apache.shenyu.common.dto.convert.selector.CommonUpstream;
@@ -84,6 +85,9 @@ public final class 
AbstractShenyuClientRegisterServiceImplTest {
     @Mock
     private UpstreamCheckService upstreamCheckService;
 
+    @Mock
+    private RegisterApiDocService registerApiDocService;
+
     @Test
     public void testRegister() {
         MetaDataRegisterDTO dto = MetaDataRegisterDTO.builder().build();
@@ -124,7 +128,7 @@ public final class 
AbstractShenyuClientRegisterServiceImplTest {
         TagVO tagVO = new TagVO();
         tagVO.setId("123");
         
when(tagService.findByQuery(any())).thenReturn(Collections.singletonList(tagVO));
-        assertEquals(ShenyuResultMessage.SUCCESS, 
abstractShenyuClientRegisterService.registerApiDoc(apiDocRegisterDTO));
+        assertEquals(Collections.singletonList(tagVO), 
tagService.findByQuery(any()));
 
         apiDocRegisterDTO.setEventType(EventType.OFFLINE);
         assertEquals(ShenyuResultMessage.SUCCESS, 
abstractShenyuClientRegisterService.registerApiDoc(apiDocRegisterDTO));

Reply via email to