Переглянути джерело

feat:后端项目,引入调用openAPI的sdk进行接口调用,后台新增一个在线调试接口

yang yi 10 місяців тому
батько
коміт
da0fabdee2

+ 5 - 0
pom.xml

@@ -75,6 +75,11 @@
             <groupId>com.github.ben-manes.caffeine</groupId>
             <artifactId>caffeine</artifactId>
         </dependency>
+        <dependency>
+            <groupId>space.anyi</groupId>
+            <artifactId>open-api-sdk</artifactId>
+            <version>0.0.1-SNAPSHOT</version>
+        </dependency>
     </dependencies>
 
 </project>

+ 24 - 3
src/main/java/space/anyi/openAPI/controller/InterfaceInfoController.java

@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
+import space.anyi.client.OpenAPIClient;
 import space.anyi.openAPI.model.PageVO;
 import space.anyi.openAPI.model.ResponseResult;
 import space.anyi.openAPI.model.commom.RequestID;
@@ -14,13 +15,14 @@ import space.anyi.openAPI.model.interfaceInfo.dto.RequestAddInterfaceInfo;
 import space.anyi.openAPI.model.interfaceInfo.dto.RequestPageInterfaceInfo;
 import space.anyi.openAPI.model.interfaceInfo.dto.RequestUpdateInterfaceInfo;
 import space.anyi.openAPI.model.interfaceInfo.vo.InterfaceInfoVO;
+import space.anyi.openAPI.model.interfaceParam.dto.RequestOnlineDebugParam;
 import space.anyi.openAPI.service.InterfaceInfoService;
 import space.anyi.openAPI.util.BeanCopyUtil;
 import space.anyi.openAPI.util.SecurityUtils;
 
-import javax.annotation.Resource;
 import java.util.List;
 import java.util.Objects;
+import java.util.concurrent.atomic.AtomicReference;
 
 /**
  * @ProjectName: yangyi-open-api-platform
@@ -32,8 +34,14 @@ import java.util.Objects;
 @RestController
 @RequestMapping("/interfaceInfo")
 public class InterfaceInfoController {
-    @Resource
-    private InterfaceInfoService interfaceInfoService;
+    private final InterfaceInfoService interfaceInfoService;
+    private final OpenAPIClient openAPIClient;
+
+    public InterfaceInfoController(InterfaceInfoService interfaceInfoService, OpenAPIClient openAPIClient) {
+        this.interfaceInfoService = interfaceInfoService;
+        this.openAPIClient = openAPIClient;
+    }
+
     @PostMapping
     @PreAuthorize("@ps.hasRole('管理员')")
     public ResponseResult add(@RequestBody RequestAddInterfaceInfo requestAddInterfaceInfo){
@@ -114,4 +122,17 @@ public class InterfaceInfoController {
         InterfaceInfoVO vo = BeanCopyUtil.copyBean(interfaceInfo, InterfaceInfoVO.class);
         return ResponseResult.okResult(vo);
     }
+    @PostMapping("/onlineDebug")
+    public ResponseResult onlineDebug(@RequestBody RequestOnlineDebugParam requestOnlineDebugParam){
+        //校验
+        //模拟参数构建
+        AtomicReference<String> name = new AtomicReference<>("");
+        requestOnlineDebugParam.getParams().stream().forEach(debugParam -> {
+            if ("name".equals(debugParam.getName())) {
+                name.set(debugParam.getValue());
+            }
+        });
+        //是sdk通过的对象进行接口调用操作
+        return ResponseResult.okResult(openAPIClient.handler(requestOnlineDebugParam.getPath(),name.get()));
+    }
 }

+ 32 - 0
src/main/java/space/anyi/openAPI/model/interfaceParam/dto/DebugParam.java

@@ -0,0 +1,32 @@
+package space.anyi.openAPI.model.interfaceParam.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @ProjectName: yangyi-open-api-platform
+ * @FileName: DebugParam
+ * @Author: 杨逸
+ * @Data:2025/10/28 11:35
+ * @Description:
+ */
+@ApiModel("在线调试参数")
+@Data
+public class DebugParam {
+    @NotEmpty(message = "参数名不能为空")
+    @ApiModelProperty(value = "参数名",required = true)
+    private String name;
+    @NotEmpty(message = "参数值不能为空")
+    @ApiModelProperty(value = "参数值",required = true)
+    private String value;
+    @NotNull(message = "参数类型不能为null")
+    @ApiModelProperty(value = "参数类型",required = true)
+    private Integer type;
+    @NotEmpty(message = "参数数据类型不能为空")
+    @ApiModelProperty(value = "参数数据类型",required = true,example = "string,number,boolean,object,array")
+    private String paramType;
+}

+ 25 - 0
src/main/java/space/anyi/openAPI/model/interfaceParam/dto/RequestOnlineDebugParam.java

@@ -0,0 +1,25 @@
+package space.anyi.openAPI.model.interfaceParam.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotEmpty;
+import java.util.List;
+
+/**
+ * @ProjectName: yangyi-open-api-platform
+ * @FileName: RequestOnlineDebugParam
+ * @Author: 杨逸
+ * @Data:2025/10/28 11:34
+ * @Description:
+ */
+@ApiModel("在线调试请求参数列表")
+@Data
+public class RequestOnlineDebugParam {
+    @NotEmpty(message = "接口路径不能为空")
+    @ApiModelProperty(value = "接口路径",required = true)
+    private String path;
+    @ApiModelProperty("参数列表")
+    private List<DebugParam> params;
+}

+ 4 - 0
src/main/resources/application.yaml

@@ -20,3 +20,7 @@ mybatis-plus:
   configuration:
     log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
   mapper-locations: classpath:/mapper/*.xml
+open-api:
+  url: http://localhost:10002
+  access-key: accessKey
+  secret-key: secretKey