TRX 1 год назад
Родитель
Сommit
dc4ec6b325

+ 46 - 0
src/main/java/com/github/microservice/models/openAPI/OpenApiInfo.java

@@ -0,0 +1,46 @@
+package com.github.microservice.models.openAPI;
+
+import lombok.Data;
+
+@Data
+public class OpenApiInfo {
+    /**
+     * 分组
+     */
+    private String group;
+
+    /**
+     * 接口名称
+     */
+    private String name;
+
+    /**
+     * 接口路径
+     */
+    private String path;
+
+    /**
+     * 请求方法
+     */
+    private String requestMethod;
+
+    /**
+     * 请求方式
+     */
+    private String contentType;
+
+    /**
+     * 描述
+     */
+    private String description;
+
+    /**
+     * 请求参数
+     */
+    private String requestParam;
+
+    /**
+     * 响应参数
+     */
+    private String responseParam;
+}

+ 21 - 0
src/main/java/com/github/microservice/models/openAPI/RefreshApiParam.java

@@ -0,0 +1,21 @@
+package com.github.microservice.models.openAPI;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class RefreshApiParam {
+
+    /**
+     * 转发uri,微服务格式为 “lb://appserver”
+     */
+    private String serverName;
+
+    /**
+     * 断言,格式为"/openApi/v2/**"
+     */
+    private String predicateArgs;
+
+    private List<OpenApiInfo> openApiInfo;
+}

+ 13 - 10
src/main/java/com/github/microservice/utils/OpenAPIScan.java

@@ -1,6 +1,8 @@
 package com.github.microservice.utils;
 
 import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.github.microservice.models.openAPI.OpenApiInfo;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 
@@ -14,8 +16,8 @@ import java.util.List;
 @Slf4j
 public class OpenAPIScan {
 
-    public static List<JSONObject> scanAPI(String str) {
-        List<JSONObject> openAPIS = new ArrayList<>();
+    public static List<OpenApiInfo> scanAPI(String str) {
+        List<OpenApiInfo> openAPIS = new ArrayList<>();
         try {
             JSONObject jsonObject = new JSONObject(str);
             JSONObject schemas = new JSONObject();
@@ -99,14 +101,15 @@ public class OpenAPIScan {
                                 response = finalSchemas.getJSONObject(responseKey);
                             }
                         }
-                        JSONObject openAPI = new JSONObject();
-                        openAPI.put("method", method);
-                        openAPI.put("path", key);
-                        openAPI.set("params", params);
-                        openAPI.set("response", response);
-                        openAPI.set("description", object.get("description"));
-                        openAPI.set("summary", object.get("summary"));
-                        openAPI.set("operationId", object.get("operationId"));
+                        OpenApiInfo openAPI = new OpenApiInfo();
+                        openAPI.setPath(key);
+                        openAPI.setRequestMethod(method);
+                        openAPI.setContentType("application/json");
+                        openAPI.setDescription(object.getStr("description"));
+                        openAPI.setName(object.getStr("operationId"));
+                        openAPI.setGroup("一卡通平台");
+                        openAPI.setRequestParam(JSONUtil.toJsonStr(params));
+                        openAPI.setResponseParam(JSONUtil.toJsonStr(response));
                         openAPIS.add(openAPI);
                     }
                 });