Copilot commented on code in PR #6050:
URL: https://github.com/apache/shenyu/pull/6050#discussion_r2194753802


##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SwaggerImportServiceImpl.java:
##########
@@ -0,0 +1,163 @@
+/*
+ * 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.impl;
+
+import org.apache.shenyu.admin.model.bean.UpstreamInstance;
+import org.apache.shenyu.admin.model.dto.SwaggerImportRequest;
+import org.apache.shenyu.admin.service.SwaggerImportService;
+import org.apache.shenyu.admin.service.manager.DocManager;
+import org.apache.shenyu.admin.utils.HttpUtils;
+import org.apache.shenyu.common.utils.GsonUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+import okhttp3.Response;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.concurrent.atomic.AtomicReference;
+import com.google.gson.JsonObject;
+
+/**
+ * Implementation of the {@link 
org.apache.shenyu.admin.service.SwaggerImportService}.
+ */
+@Service
+public class SwaggerImportServiceImpl implements SwaggerImportService {
+    
+    private static final Logger LOG = 
LoggerFactory.getLogger(SwaggerImportServiceImpl.class);
+    
+    private static final HttpUtils HTTP_UTILS = new HttpUtils();
+    
+    private final DocManager docManager;
+    
+    public SwaggerImportServiceImpl(final DocManager docManager) {
+        this.docManager = docManager;

Review Comment:
   Using a static `HttpUtils` makes it hard to mock HTTP calls in unit tests; 
consider injecting this dependency to improve testability.
   ```suggestion
       private final HttpUtils httpUtils;
       
       private final DocManager docManager;
       
       public SwaggerImportServiceImpl(final DocManager docManager, final 
HttpUtils httpUtils) {
           this.docManager = docManager;
           this.httpUtils = httpUtils;
   ```



##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/SwaggerDocParser.java:
##########
@@ -246,22 +257,35 @@ protected List<DocParameter> 
buildResponseParameterList(final JsonObject docInfo
         return respParameterList;
     }
 
-    protected List<DocParameter> buildDocParameters(final String ref, final 
JsonObject docRoot, final boolean doSubRef) {
-        JsonObject responseObject = 
docRoot.getAsJsonObject("components").getAsJsonObject("schemas").getAsJsonObject(ref);
+    protected List<DocParameter> buildDocParameters(final String ref, final 
JsonObject docRoot, 
+                                                   final boolean doSubRef, 
final SwaggerVersion version) {
+        JsonObject schemaDefinitions = getSchemaDefinitions(docRoot, version);
+        if (schemaDefinitions == null) {
+            return Collections.emptyList();
+        }
+        
+        JsonObject responseObject = schemaDefinitions.getAsJsonObject(ref);
+        if (responseObject == null) {
+            return Collections.emptyList();
+        }
+        
         JsonObject extProperties = 
responseObject.getAsJsonObject("properties");

Review Comment:
   `extProperties` duplicates `properties` retrieval. Consider removing this 
duplicate call or clarifying its intent to reduce confusion.
   ```suggestion
   
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to