From 33468c66cd08ef37a67af36fe50578a37407a82b Mon Sep 17 00:00:00 2001 From: "song.tianyang" Date: Thu, 25 Feb 2021 13:46:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0api=E6=96=87=E6=A1=A3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 接口定义增加api文档功能 --- .../api/controller/ApiDocumentController.java | 59 +- .../{ => document}/ApiDocumentInfoDTO.java | 4 +- .../{ => document}/ApiDocumentRequest.java | 3 +- .../api/dto/document/ApiDocumentShareDTO.java | 16 + .../dto/document/ApiDocumentShareRequest.java | 18 + .../dto/document/ApiDocumentShareType.java | 5 + .../ApiDocumentSimpleInfoDTO.java | 2 +- .../api/service/ApiDocumentService.java | 481 ++++++++++------ .../base/domain/ApiDocumentShare.java | 21 + .../base/domain/ApiDocumentShareExample.java | 530 ++++++++++++++++++ .../base/mapper/ApiDocumentShareMapper.java | 36 ++ .../base/mapper/ApiDocumentShareMapper.xml | 270 +++++++++ .../base/mapper/ext/ExtApiDocumentMapper.java | 7 +- .../base/mapper/ext/ExtApiDocumentMapper.xml | 9 +- .../mapper/ext/ExtApiDocumentShareMapper.java | 10 + .../mapper/ext/ExtApiDocumentShareMapper.xml | 21 + .../metersphere/commons/utils/ShiroUtils.java | 3 + frontend/package.json | 1 + .../components/document/ApiDocumentItem.vue | 224 ++++++-- .../components/document/TestScroll.vue | 66 +++ frontend/src/business/main.js | 2 + frontend/src/document/Document.vue | 62 ++ frontend/src/document/document.html | 13 + frontend/src/document/document.js | 34 ++ frontend/vue.config.js | 11 +- 25 files changed, 1668 insertions(+), 240 deletions(-) rename backend/src/main/java/io/metersphere/api/dto/{ => document}/ApiDocumentInfoDTO.java (86%) rename backend/src/main/java/io/metersphere/api/dto/{ => document}/ApiDocumentRequest.java (83%) create mode 100644 backend/src/main/java/io/metersphere/api/dto/document/ApiDocumentShareDTO.java create mode 100644 backend/src/main/java/io/metersphere/api/dto/document/ApiDocumentShareRequest.java create mode 100644 backend/src/main/java/io/metersphere/api/dto/document/ApiDocumentShareType.java rename backend/src/main/java/io/metersphere/api/dto/{ => document}/ApiDocumentSimpleInfoDTO.java (86%) create mode 100644 backend/src/main/java/io/metersphere/base/domain/ApiDocumentShare.java create mode 100644 backend/src/main/java/io/metersphere/base/domain/ApiDocumentShareExample.java create mode 100644 backend/src/main/java/io/metersphere/base/mapper/ApiDocumentShareMapper.java create mode 100644 backend/src/main/java/io/metersphere/base/mapper/ApiDocumentShareMapper.xml create mode 100644 backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDocumentShareMapper.java create mode 100644 backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDocumentShareMapper.xml create mode 100644 frontend/src/business/components/api/definition/components/document/TestScroll.vue create mode 100644 frontend/src/document/Document.vue create mode 100644 frontend/src/document/document.html create mode 100644 frontend/src/document/document.js diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiDocumentController.java b/backend/src/main/java/io/metersphere/api/controller/ApiDocumentController.java index e43dca0063..8aaf5b5975 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiDocumentController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiDocumentController.java @@ -2,19 +2,27 @@ package io.metersphere.api.controller; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import io.metersphere.api.dto.ApiDocumentInfoDTO; -import io.metersphere.api.dto.ApiDocumentRequest; -import io.metersphere.api.dto.ApiDocumentSimpleInfoDTO; +import io.metersphere.api.dto.document.ApiDocumentInfoDTO; +import io.metersphere.api.dto.document.ApiDocumentRequest; +import io.metersphere.api.dto.document.ApiDocumentShareRequest; +import io.metersphere.api.dto.document.ApiDocumentSimpleInfoDTO; +import io.metersphere.api.dto.swaggerurl.ApiDocumentShareDTO; +import io.metersphere.api.service.APITestService; import io.metersphere.api.service.ApiDefinitionService; import io.metersphere.api.service.ApiDocumentService; import io.metersphere.base.domain.ApiDefinition; import io.metersphere.base.domain.ApiDefinitionWithBLOBs; +import io.metersphere.base.domain.ApiDocumentShare; +import io.metersphere.base.domain.ApiDocumentShareExample; import lombok.Getter; import org.apache.commons.lang3.StringUtils; import org.python.antlr.ast.Str; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -32,17 +40,56 @@ public class ApiDocumentController { ApiDocumentService apiDocumentService; @Resource ApiDefinitionService apiDefinitionService; + @Resource + APITestService apiTestService; @PostMapping("/selectApiSimpleInfo") - public List list(@RequestBody ApiDocumentRequest request) { - List returnList = apiDocumentService.findApiDocumentSimpleInfoByRequest(request); + public List list(@RequestBody ApiDocumentRequest request) { + List returnList = apiDocumentService.findApiDocumentSimpleInfoByRequest(request); return returnList; } @GetMapping("/selectApiInfoById/{id}") public ApiDocumentInfoDTO selectApiInfoById(@PathVariable String id) { ApiDefinitionWithBLOBs apiModel = apiDefinitionService.getBLOBs(id); - ApiDocumentInfoDTO returnDTO = apiDocumentService.conversionModelToDTO(apiModel); + ApiDocumentInfoDTO returnDTO = new ApiDocumentInfoDTO(); + try{ + returnDTO = apiDocumentService.conversionModelToDTO(apiModel); + }catch (Exception e){ + e.printStackTrace(); + } + returnDTO.setSelectedFlag(true); return returnDTO; } + + @PostMapping("/generateApiDocumentShareInfo") + public ApiDocumentShareDTO generateApiDocumentShareInfo(@RequestBody ApiDocumentShareRequest request) { + ApiDocumentShare apiShare = apiDocumentService.generateApiDocumentShare(request); + ApiDocumentShareDTO returnDTO = apiDocumentService.conversionApiDocumentShareToDTO(apiShare); + return returnDTO; + } + + @GetMapping("/updateJmxByFile") + public String updateJmxByFile(){ + StringBuilder jmxBuilder = new StringBuilder(); + try { + String filePath = "/Users/admin/Downloads/成功吧 (20).jmx"; + File file = new File(filePath); + BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); + + String strLine = null; + while(null != (strLine = bufferedReader.readLine())){ + if(StringUtils.isNotEmpty(strLine)){ + jmxBuilder.append(strLine); + } + + } + }catch(Exception e){ + e.printStackTrace(); + } + + + String jmx = apiTestService.updateJmxString(jmxBuilder.toString(),null,false); + return jmx; + } } diff --git a/backend/src/main/java/io/metersphere/api/dto/ApiDocumentInfoDTO.java b/backend/src/main/java/io/metersphere/api/dto/document/ApiDocumentInfoDTO.java similarity index 86% rename from backend/src/main/java/io/metersphere/api/dto/ApiDocumentInfoDTO.java rename to backend/src/main/java/io/metersphere/api/dto/document/ApiDocumentInfoDTO.java index ab0e50c00c..81b8cadd82 100644 --- a/backend/src/main/java/io/metersphere/api/dto/ApiDocumentInfoDTO.java +++ b/backend/src/main/java/io/metersphere/api/dto/document/ApiDocumentInfoDTO.java @@ -1,4 +1,4 @@ -package io.metersphere.api.dto; +package io.metersphere.api.dto.document; import lombok.Getter; import lombok.Setter; @@ -13,6 +13,7 @@ import lombok.Setter; public class ApiDocumentInfoDTO { private String id; private String method; + private boolean selectedFlag; private String uri; private String name; private String status; @@ -32,5 +33,6 @@ public class ApiDocumentInfoDTO { private String responseBodyStrutureData; private String responseCode; + private boolean sharePopoverVisible = false; } diff --git a/backend/src/main/java/io/metersphere/api/dto/ApiDocumentRequest.java b/backend/src/main/java/io/metersphere/api/dto/document/ApiDocumentRequest.java similarity index 83% rename from backend/src/main/java/io/metersphere/api/dto/ApiDocumentRequest.java rename to backend/src/main/java/io/metersphere/api/dto/document/ApiDocumentRequest.java index e517a1f130..adbd944c85 100644 --- a/backend/src/main/java/io/metersphere/api/dto/ApiDocumentRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/document/ApiDocumentRequest.java @@ -1,4 +1,4 @@ -package io.metersphere.api.dto; +package io.metersphere.api.dto.document; import lombok.Getter; import lombok.Setter; @@ -19,4 +19,5 @@ public class ApiDocumentRequest { private String name; private String type; private String orderCondition; + private List apiIdList; } diff --git a/backend/src/main/java/io/metersphere/api/dto/document/ApiDocumentShareDTO.java b/backend/src/main/java/io/metersphere/api/dto/document/ApiDocumentShareDTO.java new file mode 100644 index 0000000000..39b4681ab3 --- /dev/null +++ b/backend/src/main/java/io/metersphere/api/dto/document/ApiDocumentShareDTO.java @@ -0,0 +1,16 @@ +package io.metersphere.api.dto.document; + +import lombok.Getter; +import lombok.Setter; + +/** + * @author song.tianyang + * @Date 2021/2/23 5:10 下午 + * @Description + */ +@Getter +@Setter +public class ApiDocumentShareDTO { + private String id; + private String shareUrl; +} diff --git a/backend/src/main/java/io/metersphere/api/dto/document/ApiDocumentShareRequest.java b/backend/src/main/java/io/metersphere/api/dto/document/ApiDocumentShareRequest.java new file mode 100644 index 0000000000..7b4d206155 --- /dev/null +++ b/backend/src/main/java/io/metersphere/api/dto/document/ApiDocumentShareRequest.java @@ -0,0 +1,18 @@ +package io.metersphere.api.dto.document; + +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +/** + * @author song.tianyang + * @Date 2021/2/23 5:04 下午 + * @Description + */ +@Getter +@Setter +public class ApiDocumentShareRequest { + private String shareType; + private List shareApiIdList; +} diff --git a/backend/src/main/java/io/metersphere/api/dto/document/ApiDocumentShareType.java b/backend/src/main/java/io/metersphere/api/dto/document/ApiDocumentShareType.java new file mode 100644 index 0000000000..91982b5830 --- /dev/null +++ b/backend/src/main/java/io/metersphere/api/dto/document/ApiDocumentShareType.java @@ -0,0 +1,5 @@ +package io.metersphere.api.dto.document; + +public enum ApiDocumentShareType { + Single,Batch +} diff --git a/backend/src/main/java/io/metersphere/api/dto/ApiDocumentSimpleInfoDTO.java b/backend/src/main/java/io/metersphere/api/dto/document/ApiDocumentSimpleInfoDTO.java similarity index 86% rename from backend/src/main/java/io/metersphere/api/dto/ApiDocumentSimpleInfoDTO.java rename to backend/src/main/java/io/metersphere/api/dto/document/ApiDocumentSimpleInfoDTO.java index 9f2a2bd6cc..b575665546 100644 --- a/backend/src/main/java/io/metersphere/api/dto/ApiDocumentSimpleInfoDTO.java +++ b/backend/src/main/java/io/metersphere/api/dto/document/ApiDocumentSimpleInfoDTO.java @@ -1,4 +1,4 @@ -package io.metersphere.api.dto; +package io.metersphere.api.dto.document; import lombok.Getter; import lombok.Setter; diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDocumentService.java b/backend/src/main/java/io/metersphere/api/service/ApiDocumentService.java index 08a67d60c0..3ee2dd154e 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDocumentService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDocumentService.java @@ -1,21 +1,31 @@ package io.metersphere.api.service; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import io.metersphere.api.dto.ApiDocumentInfoDTO; -import io.metersphere.api.dto.ApiDocumentRequest; -import io.metersphere.api.dto.ApiDocumentSimpleInfoDTO; +import io.metersphere.api.dto.document.ApiDocumentInfoDTO; +import io.metersphere.api.dto.document.ApiDocumentRequest; +import io.metersphere.api.dto.document.ApiDocumentShareRequest; +import io.metersphere.api.dto.document.ApiDocumentSimpleInfoDTO; +import io.metersphere.api.dto.document.ApiDocumentShareType; +import io.metersphere.api.dto.swaggerurl.ApiDocumentShareDTO; import io.metersphere.base.domain.ApiDefinitionWithBLOBs; +import io.metersphere.base.domain.ApiDocumentShare; +import io.metersphere.base.domain.ApiDocumentShareExample; +import io.metersphere.base.mapper.ApiDocumentShareMapper; import io.metersphere.base.mapper.ext.ExtApiDocumentMapper; +import io.metersphere.base.mapper.ext.ExtApiDocumentShareMapper; +import io.metersphere.commons.exception.MSException; +import io.metersphere.commons.utils.SessionUtils; +import io.metersphere.dto.BaseSystemConfigDTO; +import io.metersphere.i18n.Translator; +import io.metersphere.service.SystemParameterService; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author song.tianyang @@ -28,9 +38,50 @@ public class ApiDocumentService { @Resource ExtApiDocumentMapper extApiDocumentMapper; + @Resource + ApiDocumentShareMapper apiDocumentShareMapper; + @Resource + ExtApiDocumentShareMapper extApiDocumentShareMapper; + @Resource + SystemParameterService systemParameterService; - public List findApiDocumentSimpleInfoByRequest(ApiDocumentRequest request) { - return extApiDocumentMapper.findApiDocumentSimpleInfoByRequest(request); + public List findApiDocumentSimpleInfoByRequest(ApiDocumentRequest request) { + if (this.isParamLegitimacy(request)) { + if (request.getProjectId() == null) { + List shareIdList = this.selectShareIdByApiDocumentShareId(request.getShareId()); + request.setApiIdList(shareIdList); + return extApiDocumentMapper.findApiDocumentSimpleInfoByRequest(request); + }else { + return extApiDocumentMapper.findApiDocumentSimpleInfoByRequest(request); + } + } else { + return new ArrayList<>(); + } + } + + private List selectShareIdByApiDocumentShareId(String shareId) { + List shareApiIdList = new ArrayList<>(); + ApiDocumentShare share = apiDocumentShareMapper.selectByPrimaryKey(shareId); + if(share!=null){ + try{ + JSONArray jsonArray = JSONArray.parseArray(share.getShareApiId()); + for (int i = 0; i < jsonArray.size(); i++) { + String apiId = jsonArray.getString(i); + shareApiIdList.add(apiId); + } + }catch (Exception e){ + e.printStackTrace(); + } + } + return shareApiIdList; + } + + //参数是否合法 + private boolean isParamLegitimacy(ApiDocumentRequest request) { + if (StringUtils.isAllEmpty(request.getProjectId(), request.getShareId())) { + return false; + } + return true; } public ApiDocumentInfoDTO conversionModelToDTO(ApiDefinitionWithBLOBs apiModel) { @@ -43,208 +94,276 @@ public class ApiDocumentService { apiInfoDTO.setUri(apiModel.getPath()); apiInfoDTO.setStatus(apiModel.getStatus()); - JSONObject requestJsonObj = JSONObject.parseObject(apiModel.getRequest()); - //head赋值 - if (requestJsonObj.containsKey("headers")) { - JSONArray requestHeadDataArr = new JSONArray(); - //head赋值 - JSONArray headArr = requestJsonObj.getJSONArray("headers"); - for (int index = 0; index < headArr.size(); index++) { - JSONObject headObj = headArr.getJSONObject(index); - if (headObj.containsKey("name") && headObj.containsKey("value")) { - requestHeadDataArr.add(headObj); - } - } - apiInfoDTO.setRequestHead(requestHeadDataArr.toJSONString()); - } - //url参数赋值 - JSONArray urlParamArr = new JSONArray(); - if (requestJsonObj.containsKey("arguments")) { - //urlParam -- query赋值 - JSONArray headArr = requestJsonObj.getJSONArray("arguments"); - for (int index = 0; index < headArr.size(); index++) { - JSONObject headObj = headArr.getJSONObject(index); - if (headObj.containsKey("name") && headObj.containsKey("value")) { - urlParamArr.add(headObj); - } - } - } - if (requestJsonObj.containsKey("rest")) { - //urlParam -- rest赋值 - JSONArray headArr = requestJsonObj.getJSONArray("rest"); - for (int index = 0; index < headArr.size(); index++) { - JSONObject headObj = headArr.getJSONObject(index); - if (headObj.containsKey("name") && headObj.containsKey("value")) { - urlParamArr.add(headObj); - } - } - } - apiInfoDTO.setUrlParams(urlParamArr.toJSONString()); - //请求体参数类型 - if (requestJsonObj.containsKey("body")) { - JSONObject bodyObj = requestJsonObj.getJSONObject("body"); - if (bodyObj.containsKey("type")) { - String type = bodyObj.getString("type"); - if(StringUtils.equals(type,"WWW_FORM")){ - apiInfoDTO.setRequestBodyParamType("x-www-from-urlencoded"); - }else if(StringUtils.equals(type,"Form Data")) { - apiInfoDTO.setRequestBodyParamType("form-data"); - }else { - apiInfoDTO.setRequestBodyParamType(type); - } - if (StringUtils.equals(type, "JSON")) { - //判断是否是JsonSchema - boolean isJsonSchema = false; - if(bodyObj.containsKey("format")){ - String foramtValue = String.valueOf(bodyObj.get("format")); - if(StringUtils.equals("JSON-SCHEMA",foramtValue)){ - isJsonSchema = true; - } + if (apiModel.getRequest() != null) { + JSONObject requestJsonObj = JSONObject.parseObject(apiModel.getRequest()); + //head赋值 + if (requestJsonObj.containsKey("headers")) { + JSONArray requestHeadDataArr = new JSONArray(); + //head赋值 + JSONArray headArr = requestJsonObj.getJSONArray("headers"); + for (int index = 0; index < headArr.size(); index++) { + JSONObject headObj = headArr.getJSONObject(index); + if (headObj.containsKey("name") && headObj.containsKey("value")) { + requestHeadDataArr.add(headObj); } - if(isJsonSchema){ - apiInfoDTO.setRequestBodyParamType("JSON-SCHEMA"); - apiInfoDTO.setJsonSchemaBody(bodyObj); - }else { + } + apiInfoDTO.setRequestHead(requestHeadDataArr.toJSONString()); + } + //url参数赋值 + JSONArray urlParamArr = new JSONArray(); + if (requestJsonObj.containsKey("arguments")) { + //urlParam -- query赋值 + JSONArray headArr = requestJsonObj.getJSONArray("arguments"); + for (int index = 0; index < headArr.size(); index++) { + JSONObject headObj = headArr.getJSONObject(index); + if (headObj.containsKey("name") && headObj.containsKey("value")) { + urlParamArr.add(headObj); + } + } + } + if (requestJsonObj.containsKey("rest")) { + //urlParam -- rest赋值 + JSONArray headArr = requestJsonObj.getJSONArray("rest"); + for (int index = 0; index < headArr.size(); index++) { + JSONObject headObj = headArr.getJSONObject(index); + if (headObj.containsKey("name") && headObj.containsKey("value")) { + urlParamArr.add(headObj); + } + } + } + apiInfoDTO.setUrlParams(urlParamArr.toJSONString()); + //请求体参数类型 + if (requestJsonObj.containsKey("body")) { + JSONObject bodyObj = requestJsonObj.getJSONObject("body"); + if (bodyObj.containsKey("type")) { + String type = bodyObj.getString("type"); + if (StringUtils.equals(type, "WWW_FORM")) { + apiInfoDTO.setRequestBodyParamType("x-www-from-urlencoded"); + } else if (StringUtils.equals(type, "Form Data")) { + apiInfoDTO.setRequestBodyParamType("form-data"); + } else { + apiInfoDTO.setRequestBodyParamType(type); + } + + if (StringUtils.equals(type, "JSON")) { + //判断是否是JsonSchema + boolean isJsonSchema = false; + if (bodyObj.containsKey("format")) { + String foramtValue = String.valueOf(bodyObj.get("format")); + if (StringUtils.equals("JSON-SCHEMA", foramtValue)) { + isJsonSchema = true; + } + } + if (isJsonSchema) { + apiInfoDTO.setRequestBodyParamType("JSON-SCHEMA"); + apiInfoDTO.setJsonSchemaBody(bodyObj); + } else { + if (bodyObj.containsKey("raw")) { + String raw = bodyObj.getString("raw"); + apiInfoDTO.setRequestBodyStrutureData(raw); + previewObj = JSONObject.parseObject(raw); + } + } + } else if (StringUtils.equalsAny(type, "XML", "Raw")) { if (bodyObj.containsKey("raw")) { String raw = bodyObj.getString("raw"); apiInfoDTO.setRequestBodyStrutureData(raw); previewObj = JSONObject.parseObject(raw); } - } - } else if (StringUtils.equalsAny(type, "XML", "Raw")) { - if (bodyObj.containsKey("raw")) { - String raw = bodyObj.getString("raw"); - apiInfoDTO.setRequestBodyStrutureData(raw); - previewObj = JSONObject.parseObject(raw); - } - } else if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) { - if (bodyObj.containsKey("kvs")) { - JSONArray bodyParamArr = new JSONArray(); - JSONArray kvsArr = bodyObj.getJSONArray("kvs"); - for (int i = 0; i < kvsArr.size(); i++) { - JSONObject kv = kvsArr.getJSONObject(i); - if (kv.containsKey("name")&&kv.containsKey("value")) { - bodyParamArr.add(kv); - previewObj.put(String.valueOf(kv.get("name")),String.valueOf(kv.get("value"))); - } - } - apiInfoDTO.setRequestBodyFormData(bodyParamArr.toJSONString()); - } - } else if (StringUtils.equals(type, "BINARY")) { - if (bodyObj.containsKey("binary")) { - List> bodyParamList = new ArrayList<>(); - JSONArray kvsArr = bodyObj.getJSONArray("binary"); - for (int i = 0; i < kvsArr.size(); i++) { - JSONObject kv = kvsArr.getJSONObject(i); - if (kv.containsKey("description") && kv.containsKey("files")) { - Map bodyMap = new HashMap<>(); - String name = kv.getString("description"); - JSONArray fileArr = kv.getJSONArray("files"); - String value = ""; - for (int j = 0; j < fileArr.size(); j++) { - JSONObject fileObj = fileArr.getJSONObject(j); - if (fileObj.containsKey("name")) { - value += fileObj.getString("name") + " ;"; - } + } else if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) { + if (bodyObj.containsKey("kvs")) { + JSONArray bodyParamArr = new JSONArray(); + JSONArray kvsArr = bodyObj.getJSONArray("kvs"); + for (int i = 0; i < kvsArr.size(); i++) { + JSONObject kv = kvsArr.getJSONObject(i); + if (kv.containsKey("name") && kv.containsKey("value")) { + bodyParamArr.add(kv); + previewObj.put(String.valueOf(kv.get("name")), String.valueOf(kv.get("value"))); } - bodyMap.put("name", name); - bodyMap.put("value", value); - bodyMap.put("contentType", "File"); - bodyParamList.add(bodyMap); - - previewObj.put(String.valueOf(name),String.valueOf(value)); } + apiInfoDTO.setRequestBodyFormData(bodyParamArr.toJSONString()); + } + } else if (StringUtils.equals(type, "BINARY")) { + if (bodyObj.containsKey("binary")) { + List> bodyParamList = new ArrayList<>(); + JSONArray kvsArr = bodyObj.getJSONArray("binary"); + for (int i = 0; i < kvsArr.size(); i++) { + JSONObject kv = kvsArr.getJSONObject(i); + if (kv.containsKey("description") && kv.containsKey("files")) { + Map bodyMap = new HashMap<>(); + String name = kv.getString("description"); + JSONArray fileArr = kv.getJSONArray("files"); + String value = ""; + for (int j = 0; j < fileArr.size(); j++) { + JSONObject fileObj = fileArr.getJSONObject(j); + if (fileObj.containsKey("name")) { + value += fileObj.getString("name") + " ;"; + } + } + bodyMap.put("name", name); + bodyMap.put("value", value); + bodyMap.put("contentType", "File"); + bodyParamList.add(bodyMap); + + previewObj.put(String.valueOf(name), String.valueOf(value)); + } + } + apiInfoDTO.setRequestBodyFormData(JSONArray.toJSONString(bodyParamList)); } - apiInfoDTO.setRequestBodyFormData(JSONArray.toJSONString(bodyParamList)); } } } } - JSONObject responseJsonObj = JSONObject.parseObject(apiModel.getResponse()); + //赋值响应头 - if (responseJsonObj.containsKey("headers")) { - JSONArray responseHeadDataArr = new JSONArray(); - JSONArray headArr = responseJsonObj.getJSONArray("headers"); - for (int index = 0; index < headArr.size(); index++) { - JSONObject headObj = headArr.getJSONObject(index); - if (headObj.containsKey("name") && headObj.containsKey("value")) { - responseHeadDataArr.add(headObj); + if (apiModel.getResponse() != null) { + JSONObject responseJsonObj = JSONObject.parseObject(apiModel.getResponse()); + if (responseJsonObj.containsKey("headers")) { + JSONArray responseHeadDataArr = new JSONArray(); + JSONArray headArr = responseJsonObj.getJSONArray("headers"); + for (int index = 0; index < headArr.size(); index++) { + JSONObject headObj = headArr.getJSONObject(index); + if (headObj.containsKey("name") && headObj.containsKey("value")) { + responseHeadDataArr.add(headObj); + } } + apiInfoDTO.setResponseHead(responseHeadDataArr.toJSONString()); } - apiInfoDTO.setResponseHead(responseHeadDataArr.toJSONString()); - } - // 赋值响应体 - if (responseJsonObj.containsKey("body")) { - JSONObject bodyObj = responseJsonObj.getJSONObject("body"); - if (bodyObj.containsKey("type")) { - String type = bodyObj.getString("type"); - if(StringUtils.equals(type,"WWW_FORM")){ - apiInfoDTO.setResponseBodyParamType("x-www-from-urlencoded"); - }else if(StringUtils.equals(type,"Form Data")) { - apiInfoDTO.setResponseBodyParamType("form-data"); - }else { - apiInfoDTO.setResponseBodyParamType(type); - } - if (StringUtils.equalsAny(type, "JSON", "XML", "Raw")) { - if (bodyObj.containsKey("raw")) { - String raw = bodyObj.getString("raw"); - apiInfoDTO.setResponseBodyStrutureData(raw); + // 赋值响应体 + if (responseJsonObj.containsKey("body")) { + JSONObject bodyObj = responseJsonObj.getJSONObject("body"); + if (bodyObj.containsKey("type")) { + String type = bodyObj.getString("type"); + if (StringUtils.equals(type, "WWW_FORM")) { + apiInfoDTO.setResponseBodyParamType("x-www-from-urlencoded"); + } else if (StringUtils.equals(type, "Form Data")) { + apiInfoDTO.setResponseBodyParamType("form-data"); + } else { + apiInfoDTO.setResponseBodyParamType(type); } - } else if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) { - if (bodyObj.containsKey("kvs")) { - JSONArray bodyParamArr = new JSONArray(); - JSONArray kvsArr = bodyObj.getJSONArray("kvs"); - for (int i = 0; i < kvsArr.size(); i++) { - JSONObject kv = kvsArr.getJSONObject(i); - if (kv.containsKey("name")) { - bodyParamArr.add(kv); - } + if (StringUtils.equalsAny(type, "JSON", "XML", "Raw")) { + if (bodyObj.containsKey("raw")) { + String raw = bodyObj.getString("raw"); + apiInfoDTO.setResponseBodyStrutureData(raw); } - apiInfoDTO.setResponseBodyFormData(bodyParamArr.toJSONString()); - } - } else if (StringUtils.equals(type, "BINARY")) { - if (bodyObj.containsKey("binary")) { - List> bodyParamList = new ArrayList<>(); - JSONArray kvsArr = bodyObj.getJSONArray("kvs"); - for (int i = 0; i < kvsArr.size(); i++) { - JSONObject kv = kvsArr.getJSONObject(i); - if (kv.containsKey("description") && kv.containsKey("files")) { - Map bodyMap = new HashMap<>(); - - String name = kv.getString("description"); - JSONArray fileArr = kv.getJSONArray("files"); - String value = ""; - for (int j = 0; j < fileArr.size(); j++) { - JSONObject fileObj = fileArr.getJSONObject(j); - if (fileObj.containsKey("name")) { - value += fileObj.getString("name") + " ;"; - } + } else if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) { + if (bodyObj.containsKey("kvs")) { + JSONArray bodyParamArr = new JSONArray(); + JSONArray kvsArr = bodyObj.getJSONArray("kvs"); + for (int i = 0; i < kvsArr.size(); i++) { + JSONObject kv = kvsArr.getJSONObject(i); + if (kv.containsKey("name")) { + bodyParamArr.add(kv); } - bodyMap.put("name", name); - bodyMap.put("value", value); - bodyParamList.add(bodyMap); } + apiInfoDTO.setResponseBodyFormData(bodyParamArr.toJSONString()); + } + } else if (StringUtils.equals(type, "BINARY")) { + if (bodyObj.containsKey("binary")) { + List> bodyParamList = new ArrayList<>(); + JSONArray kvsArr = bodyObj.getJSONArray("kvs"); + for (int i = 0; i < kvsArr.size(); i++) { + JSONObject kv = kvsArr.getJSONObject(i); + if (kv.containsKey("description") && kv.containsKey("files")) { + Map bodyMap = new HashMap<>(); + + String name = kv.getString("description"); + JSONArray fileArr = kv.getJSONArray("files"); + String value = ""; + for (int j = 0; j < fileArr.size(); j++) { + JSONObject fileObj = fileArr.getJSONObject(j); + if (fileObj.containsKey("name")) { + value += fileObj.getString("name") + " ;"; + } + } + bodyMap.put("name", name); + bodyMap.put("value", value); + bodyParamList.add(bodyMap); + } + } + apiInfoDTO.setResponseBodyFormData(JSONArray.toJSONString(bodyParamList)); } - apiInfoDTO.setResponseBodyFormData(JSONArray.toJSONString(bodyParamList)); } } } - } - // 赋值响应码 - if (responseJsonObj.containsKey("statusCode")) { - JSONArray responseStatusDataArr = new JSONArray(); - JSONArray statusArr = responseJsonObj.getJSONArray("statusCode"); - for (int index = 0; index < statusArr.size(); index++) { - JSONObject statusObj = statusArr.getJSONObject(index); - if (statusObj.containsKey("name") && statusObj.containsKey("value")) { - responseStatusDataArr.add(statusObj); + // 赋值响应码 + if (responseJsonObj.containsKey("statusCode")) { + JSONArray responseStatusDataArr = new JSONArray(); + JSONArray statusArr = responseJsonObj.getJSONArray("statusCode"); + for (int index = 0; index < statusArr.size(); index++) { + JSONObject statusObj = statusArr.getJSONObject(index); + if (statusObj.containsKey("name") && statusObj.containsKey("value")) { + responseStatusDataArr.add(statusObj); + } } + apiInfoDTO.setResponseCode(responseStatusDataArr.toJSONString()); } - apiInfoDTO.setResponseCode(responseStatusDataArr.toJSONString()); } } apiInfoDTO.setRequestPreviewData(previewObj); return apiInfoDTO; } + + /** + * 生成 api接口文档分享信息 + * 根据要分享的api_id和分享方式来进行完全匹配搜索。 + * 搜索的到就返回那条数据,搜索不到就新增一条信息 + * @param request 入参 + * @return ApiDocumentShare数据对象 + */ + public ApiDocumentShare generateApiDocumentShare(ApiDocumentShareRequest request) { + ApiDocumentShare apiDocumentShare = null; + if (request.getShareApiIdList() != null && !request.getShareApiIdList().isEmpty() + &&StringUtils.equalsAny(request.getShareType(), ApiDocumentShareType.Single.name(),ApiDocumentShareType.Batch.name())) { + //将ID进行排序 + List apiDocumentShareList = this.findByShareTypeAndShareApiIdWithBLOBs(request.getShareType(),request.getShareApiIdList()); + if(apiDocumentShareList.isEmpty()){ + String shareApiIdJsonArrayString = this.genShareIdJsonString(request.getShareApiIdList()); + long createTime = System.currentTimeMillis(); + + apiDocumentShare = new ApiDocumentShare(); + apiDocumentShare.setId(UUID.randomUUID().toString()); + apiDocumentShare.setShareApiId(shareApiIdJsonArrayString); + apiDocumentShare.setCreateUserId(SessionUtils.getUserId()); + apiDocumentShare.setCreateTime(createTime); + apiDocumentShare.setUpdateTime(createTime); + apiDocumentShare.setShareType(request.getShareType()); + apiDocumentShareMapper.insert(apiDocumentShare); + }else { + return apiDocumentShareList.get(0); + } + } + + if(apiDocumentShare==null){ + apiDocumentShare = new ApiDocumentShare(); + } + return apiDocumentShare; + } + + private List findByShareTypeAndShareApiIdWithBLOBs(String shareType, List shareApiIdList) { + String shareApiIdString = this.genShareIdJsonString(shareApiIdList); + return extApiDocumentShareMapper.selectByShareTypeAndShareApiIdWithBLOBs(shareType,shareApiIdString); + } + + /** + * 根据treeSet排序生成apiId的Jsonarray字符串 + * @param shareApiIdList 要分享的ID集合 + * @return 要分享的ID JSON格式字符串 + */ + private String genShareIdJsonString(Collection shareApiIdList) { + TreeSet treeSet = new TreeSet<>(shareApiIdList); + return JSONArray.toJSONString(treeSet); + } + + public ApiDocumentShareDTO conversionApiDocumentShareToDTO(ApiDocumentShare apiShare) { + ApiDocumentShareDTO returnDTO = new ApiDocumentShareDTO(); + if(!StringUtils.isEmpty(apiShare.getShareApiId())){ + BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); + String url = "/#/apiDocumentInfo?documentId=" + apiShare.getId(); + returnDTO.setId(apiShare.getId()); + returnDTO.setShareUrl(url); + } + return returnDTO; + } } diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiDocumentShare.java b/backend/src/main/java/io/metersphere/base/domain/ApiDocumentShare.java new file mode 100644 index 0000000000..74c3cea630 --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/domain/ApiDocumentShare.java @@ -0,0 +1,21 @@ +package io.metersphere.base.domain; + +import java.io.Serializable; +import lombok.Data; + +@Data +public class ApiDocumentShare implements Serializable { + private String id; + + private Long createTime; + + private String createUserId; + + private Long updateTime; + + private String shareType; + + private String shareApiId; + + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiDocumentShareExample.java b/backend/src/main/java/io/metersphere/base/domain/ApiDocumentShareExample.java new file mode 100644 index 0000000000..7743cfd01f --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/domain/ApiDocumentShareExample.java @@ -0,0 +1,530 @@ +package io.metersphere.base.domain; + +import java.util.ArrayList; +import java.util.List; + +public class ApiDocumentShareExample { + protected String orderByClause; + + protected boolean distinct; + + protected List oredCriteria; + + public ApiDocumentShareExample() { + oredCriteria = new ArrayList(); + } + + public void setOrderByClause(String orderByClause) { + this.orderByClause = orderByClause; + } + + public String getOrderByClause() { + return orderByClause; + } + + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + public boolean isDistinct() { + return distinct; + } + + public List getOredCriteria() { + return oredCriteria; + } + + public void or(Criteria criteria) { + oredCriteria.add(criteria); + } + + public Criteria or() { + Criteria criteria = createCriteriaInternal(); + oredCriteria.add(criteria); + return criteria; + } + + public Criteria createCriteria() { + Criteria criteria = createCriteriaInternal(); + if (oredCriteria.size() == 0) { + oredCriteria.add(criteria); + } + return criteria; + } + + protected Criteria createCriteriaInternal() { + Criteria criteria = new Criteria(); + return criteria; + } + + public void clear() { + oredCriteria.clear(); + orderByClause = null; + distinct = false; + } + + protected abstract static class GeneratedCriteria { + protected List criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList(); + } + + public boolean isValid() { + return criteria.size() > 0; + } + + public List getAllCriteria() { + return criteria; + } + + public List getCriteria() { + return criteria; + } + + protected void addCriterion(String condition) { + if (condition == null) { + throw new RuntimeException("Value for condition cannot be null"); + } + criteria.add(new Criterion(condition)); + } + + protected void addCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value)); + } + + protected void addCriterion(String condition, Object value1, Object value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value1, value2)); + } + + public Criteria andIdIsNull() { + addCriterion("id is null"); + return (Criteria) this; + } + + public Criteria andIdIsNotNull() { + addCriterion("id is not null"); + return (Criteria) this; + } + + public Criteria andIdEqualTo(String value) { + addCriterion("id =", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotEqualTo(String value) { + addCriterion("id <>", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThan(String value) { + addCriterion("id >", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThanOrEqualTo(String value) { + addCriterion("id >=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThan(String value) { + addCriterion("id <", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThanOrEqualTo(String value) { + addCriterion("id <=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLike(String value) { + addCriterion("id like", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotLike(String value) { + addCriterion("id not like", value, "id"); + return (Criteria) this; + } + + public Criteria andIdIn(List values) { + addCriterion("id in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdNotIn(List values) { + addCriterion("id not in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdBetween(String value1, String value2) { + addCriterion("id between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andIdNotBetween(String value1, String value2) { + addCriterion("id not between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNull() { + addCriterion("create_time is null"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNotNull() { + addCriterion("create_time is not null"); + return (Criteria) this; + } + + public Criteria andCreateTimeEqualTo(Long value) { + addCriterion("create_time =", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotEqualTo(Long value) { + addCriterion("create_time <>", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThan(Long value) { + addCriterion("create_time >", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThanOrEqualTo(Long value) { + addCriterion("create_time >=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThan(Long value) { + addCriterion("create_time <", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThanOrEqualTo(Long value) { + addCriterion("create_time <=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeIn(List values) { + addCriterion("create_time in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotIn(List values) { + addCriterion("create_time not in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeBetween(Long value1, Long value2) { + addCriterion("create_time between", value1, value2, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotBetween(Long value1, Long value2) { + addCriterion("create_time not between", value1, value2, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateUserIdIsNull() { + addCriterion("create_user_id is null"); + return (Criteria) this; + } + + public Criteria andCreateUserIdIsNotNull() { + addCriterion("create_user_id is not null"); + return (Criteria) this; + } + + public Criteria andCreateUserIdEqualTo(String value) { + addCriterion("create_user_id =", value, "createUserId"); + return (Criteria) this; + } + + public Criteria andCreateUserIdNotEqualTo(String value) { + addCriterion("create_user_id <>", value, "createUserId"); + return (Criteria) this; + } + + public Criteria andCreateUserIdGreaterThan(String value) { + addCriterion("create_user_id >", value, "createUserId"); + return (Criteria) this; + } + + public Criteria andCreateUserIdGreaterThanOrEqualTo(String value) { + addCriterion("create_user_id >=", value, "createUserId"); + return (Criteria) this; + } + + public Criteria andCreateUserIdLessThan(String value) { + addCriterion("create_user_id <", value, "createUserId"); + return (Criteria) this; + } + + public Criteria andCreateUserIdLessThanOrEqualTo(String value) { + addCriterion("create_user_id <=", value, "createUserId"); + return (Criteria) this; + } + + public Criteria andCreateUserIdLike(String value) { + addCriterion("create_user_id like", value, "createUserId"); + return (Criteria) this; + } + + public Criteria andCreateUserIdNotLike(String value) { + addCriterion("create_user_id not like", value, "createUserId"); + return (Criteria) this; + } + + public Criteria andCreateUserIdIn(List values) { + addCriterion("create_user_id in", values, "createUserId"); + return (Criteria) this; + } + + public Criteria andCreateUserIdNotIn(List values) { + addCriterion("create_user_id not in", values, "createUserId"); + return (Criteria) this; + } + + public Criteria andCreateUserIdBetween(String value1, String value2) { + addCriterion("create_user_id between", value1, value2, "createUserId"); + return (Criteria) this; + } + + public Criteria andCreateUserIdNotBetween(String value1, String value2) { + addCriterion("create_user_id not between", value1, value2, "createUserId"); + return (Criteria) this; + } + + public Criteria andUpdateTimeIsNull() { + addCriterion("update_time is null"); + return (Criteria) this; + } + + public Criteria andUpdateTimeIsNotNull() { + addCriterion("update_time is not null"); + return (Criteria) this; + } + + public Criteria andUpdateTimeEqualTo(Long value) { + addCriterion("update_time =", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeNotEqualTo(Long value) { + addCriterion("update_time <>", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeGreaterThan(Long value) { + addCriterion("update_time >", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeGreaterThanOrEqualTo(Long value) { + addCriterion("update_time >=", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeLessThan(Long value) { + addCriterion("update_time <", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeLessThanOrEqualTo(Long value) { + addCriterion("update_time <=", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeIn(List values) { + addCriterion("update_time in", values, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeNotIn(List values) { + addCriterion("update_time not in", values, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeBetween(Long value1, Long value2) { + addCriterion("update_time between", value1, value2, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeNotBetween(Long value1, Long value2) { + addCriterion("update_time not between", value1, value2, "updateTime"); + return (Criteria) this; + } + + public Criteria andShareTypeIsNull() { + addCriterion("share_type is null"); + return (Criteria) this; + } + + public Criteria andShareTypeIsNotNull() { + addCriterion("share_type is not null"); + return (Criteria) this; + } + + public Criteria andShareTypeEqualTo(String value) { + addCriterion("share_type =", value, "shareType"); + return (Criteria) this; + } + + public Criteria andShareTypeNotEqualTo(String value) { + addCriterion("share_type <>", value, "shareType"); + return (Criteria) this; + } + + public Criteria andShareTypeGreaterThan(String value) { + addCriterion("share_type >", value, "shareType"); + return (Criteria) this; + } + + public Criteria andShareTypeGreaterThanOrEqualTo(String value) { + addCriterion("share_type >=", value, "shareType"); + return (Criteria) this; + } + + public Criteria andShareTypeLessThan(String value) { + addCriterion("share_type <", value, "shareType"); + return (Criteria) this; + } + + public Criteria andShareTypeLessThanOrEqualTo(String value) { + addCriterion("share_type <=", value, "shareType"); + return (Criteria) this; + } + + public Criteria andShareTypeLike(String value) { + addCriterion("share_type like", value, "shareType"); + return (Criteria) this; + } + + public Criteria andShareTypeNotLike(String value) { + addCriterion("share_type not like", value, "shareType"); + return (Criteria) this; + } + + public Criteria andShareTypeIn(List values) { + addCriterion("share_type in", values, "shareType"); + return (Criteria) this; + } + + public Criteria andShareTypeNotIn(List values) { + addCriterion("share_type not in", values, "shareType"); + return (Criteria) this; + } + + public Criteria andShareTypeBetween(String value1, String value2) { + addCriterion("share_type between", value1, value2, "shareType"); + return (Criteria) this; + } + + public Criteria andShareTypeNotBetween(String value1, String value2) { + addCriterion("share_type not between", value1, value2, "shareType"); + return (Criteria) this; + } + } + + public static class Criteria extends GeneratedCriteria { + + protected Criteria() { + super(); + } + } + + public static class Criterion { + private String condition; + + private Object value; + + private Object secondValue; + + private boolean noValue; + + private boolean singleValue; + + private boolean betweenValue; + + private boolean listValue; + + private String typeHandler; + + public String getCondition() { + return condition; + } + + public Object getValue() { + return value; + } + + public Object getSecondValue() { + return secondValue; + } + + public boolean isNoValue() { + return noValue; + } + + public boolean isSingleValue() { + return singleValue; + } + + public boolean isBetweenValue() { + return betweenValue; + } + + public boolean isListValue() { + return listValue; + } + + public String getTypeHandler() { + return typeHandler; + } + + protected Criterion(String condition) { + super(); + this.condition = condition; + this.typeHandler = null; + this.noValue = true; + } + + protected Criterion(String condition, Object value, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.typeHandler = typeHandler; + if (value instanceof List) { + this.listValue = true; + } else { + this.singleValue = true; + } + } + + protected Criterion(String condition, Object value) { + this(condition, value, null); + } + + protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.secondValue = secondValue; + this.typeHandler = typeHandler; + this.betweenValue = true; + } + + protected Criterion(String condition, Object value, Object secondValue) { + this(condition, value, secondValue, null); + } + } +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ApiDocumentShareMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ApiDocumentShareMapper.java new file mode 100644 index 0000000000..cce13d641c --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/mapper/ApiDocumentShareMapper.java @@ -0,0 +1,36 @@ +package io.metersphere.base.mapper; + +import io.metersphere.base.domain.ApiDocumentShare; +import io.metersphere.base.domain.ApiDocumentShareExample; +import java.util.List; +import org.apache.ibatis.annotations.Param; + +public interface ApiDocumentShareMapper { + long countByExample(ApiDocumentShareExample example); + + int deleteByExample(ApiDocumentShareExample example); + + int deleteByPrimaryKey(String id); + + int insert(ApiDocumentShare record); + + int insertSelective(ApiDocumentShare record); + + List selectByExampleWithBLOBs(ApiDocumentShareExample example); + + List selectByExample(ApiDocumentShareExample example); + + ApiDocumentShare selectByPrimaryKey(String id); + + int updateByExampleSelective(@Param("record") ApiDocumentShare record, @Param("example") ApiDocumentShareExample example); + + int updateByExampleWithBLOBs(@Param("record") ApiDocumentShare record, @Param("example") ApiDocumentShareExample example); + + int updateByExample(@Param("record") ApiDocumentShare record, @Param("example") ApiDocumentShareExample example); + + int updateByPrimaryKeySelective(ApiDocumentShare record); + + int updateByPrimaryKeyWithBLOBs(ApiDocumentShare record); + + int updateByPrimaryKey(ApiDocumentShare record); +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ApiDocumentShareMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ApiDocumentShareMapper.xml new file mode 100644 index 0000000000..1a41b92a37 --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/mapper/ApiDocumentShareMapper.xml @@ -0,0 +1,270 @@ + + + + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + id, create_time, create_user_id, update_time, share_type + + + share_api_id + + + + + + delete from api_document_share + where id = #{id,jdbcType=VARCHAR} + + + delete from api_document_share + + + + + + insert into api_document_share (id, create_time, create_user_id, + update_time, share_type, share_api_id + ) + values (#{id,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{createUserId,jdbcType=VARCHAR}, + #{updateTime,jdbcType=BIGINT}, #{shareType,jdbcType=VARCHAR}, #{shareApiId,jdbcType=LONGVARCHAR} + ) + + + insert into api_document_share + + + id, + + + create_time, + + + create_user_id, + + + update_time, + + + share_type, + + + share_api_id, + + + + + #{id,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=BIGINT}, + + + #{createUserId,jdbcType=VARCHAR}, + + + #{updateTime,jdbcType=BIGINT}, + + + #{shareType,jdbcType=VARCHAR}, + + + #{shareApiId,jdbcType=LONGVARCHAR}, + + + + + + update api_document_share + + + id = #{record.id,jdbcType=VARCHAR}, + + + create_time = #{record.createTime,jdbcType=BIGINT}, + + + create_user_id = #{record.createUserId,jdbcType=VARCHAR}, + + + update_time = #{record.updateTime,jdbcType=BIGINT}, + + + share_type = #{record.shareType,jdbcType=VARCHAR}, + + + share_api_id = #{record.shareApiId,jdbcType=LONGVARCHAR}, + + + + + + + + update api_document_share + set id = #{record.id,jdbcType=VARCHAR}, + create_time = #{record.createTime,jdbcType=BIGINT}, + create_user_id = #{record.createUserId,jdbcType=VARCHAR}, + update_time = #{record.updateTime,jdbcType=BIGINT}, + share_type = #{record.shareType,jdbcType=VARCHAR}, + share_api_id = #{record.shareApiId,jdbcType=LONGVARCHAR} + + + + + + update api_document_share + set id = #{record.id,jdbcType=VARCHAR}, + create_time = #{record.createTime,jdbcType=BIGINT}, + create_user_id = #{record.createUserId,jdbcType=VARCHAR}, + update_time = #{record.updateTime,jdbcType=BIGINT}, + share_type = #{record.shareType,jdbcType=VARCHAR} + + + + + + update api_document_share + + + create_time = #{createTime,jdbcType=BIGINT}, + + + create_user_id = #{createUserId,jdbcType=VARCHAR}, + + + update_time = #{updateTime,jdbcType=BIGINT}, + + + share_type = #{shareType,jdbcType=VARCHAR}, + + + share_api_id = #{shareApiId,jdbcType=LONGVARCHAR}, + + + where id = #{id,jdbcType=VARCHAR} + + + update api_document_share + set create_time = #{createTime,jdbcType=BIGINT}, + create_user_id = #{createUserId,jdbcType=VARCHAR}, + update_time = #{updateTime,jdbcType=BIGINT}, + share_type = #{shareType,jdbcType=VARCHAR}, + share_api_id = #{shareApiId,jdbcType=LONGVARCHAR} + where id = #{id,jdbcType=VARCHAR} + + + update api_document_share + set create_time = #{createTime,jdbcType=BIGINT}, + create_user_id = #{createUserId,jdbcType=VARCHAR}, + update_time = #{updateTime,jdbcType=BIGINT}, + share_type = #{shareType,jdbcType=VARCHAR} + where id = #{id,jdbcType=VARCHAR} + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDocumentMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDocumentMapper.java index e53c1db803..5ae51e0614 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDocumentMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDocumentMapper.java @@ -1,11 +1,12 @@ package io.metersphere.base.mapper.ext; -import io.metersphere.api.dto.ApiDocumentRequest; -import io.metersphere.api.dto.ApiDocumentSimpleInfoDTO; +import io.metersphere.api.dto.document.ApiDocumentInfoDTO; +import io.metersphere.api.dto.document.ApiDocumentRequest; +import io.metersphere.api.dto.document.ApiDocumentSimpleInfoDTO; import org.apache.ibatis.annotations.Param; import java.util.List; public interface ExtApiDocumentMapper { - List findApiDocumentSimpleInfoByRequest(@Param("request") ApiDocumentRequest request); + List findApiDocumentSimpleInfoByRequest(@Param("request") ApiDocumentRequest request); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDocumentMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDocumentMapper.xml index 655c980f30..c39fe7505e 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDocumentMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDocumentMapper.xml @@ -1,7 +1,7 @@ - SELECT api.id,api.name FROM Api_definition api @@ -13,13 +13,18 @@ AND api.method = #{request.type} - AND api.module_id in #{nodeId} + + AND api.id in + + #{apiId} + + ORDER BY api.create_time DESC diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDocumentShareMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDocumentShareMapper.java new file mode 100644 index 0000000000..184c541e32 --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDocumentShareMapper.java @@ -0,0 +1,10 @@ +package io.metersphere.base.mapper.ext; + +import io.metersphere.base.domain.ApiDocumentShare; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface ExtApiDocumentShareMapper { + List selectByShareTypeAndShareApiIdWithBLOBs(@Param("shareType") String shareType, @Param("shareApiId") String shareApiIdString); +} diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDocumentShareMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDocumentShareMapper.xml new file mode 100644 index 0000000000..090216361b --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDocumentShareMapper.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/commons/utils/ShiroUtils.java b/backend/src/main/java/io/metersphere/commons/utils/ShiroUtils.java index 27430e98ae..476dec1c96 100644 --- a/backend/src/main/java/io/metersphere/commons/utils/ShiroUtils.java +++ b/backend/src/main/java/io/metersphere/commons/utils/ShiroUtils.java @@ -37,6 +37,9 @@ public class ShiroUtils { filterChainDefinitionMap.put("/403", "anon"); filterChainDefinitionMap.put("/anonymous/**", "anon"); + + //api-对外文档页面提供的查询接口 + filterChainDefinitionMap.put("/api/document/**", "anon"); } public static Cookie getSessionIdCookie(){ diff --git a/frontend/package.json b/frontend/package.json index f0813079bd..8497b76b09 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -35,6 +35,7 @@ "sha.js": "^2.4.11", "vue": "^2.6.10", "vue-calendar-heatmap": "^0.8.4", + "vue-clipboard2": "^0.3.1", "vue-echarts": "^4.1.0", "vue-float-action-button": "^0.6.6", "vue-i18n": "^8.15.3", diff --git a/frontend/src/business/components/api/definition/components/document/ApiDocumentItem.vue b/frontend/src/business/components/api/definition/components/document/ApiDocumentItem.vue index 4a4488eb60..64b00bfce5 100644 --- a/frontend/src/business/components/api/definition/components/document/ApiDocumentItem.vue +++ b/frontend/src/business/components/api/definition/components/document/ApiDocumentItem.vue @@ -1,8 +1,8 @@