feat: 接口定义增加api文档功能

接口定义增加api文档功能
This commit is contained in:
song.tianyang 2021-02-25 13:46:01 +08:00
parent d903688955
commit 33468c66cd
25 changed files with 1668 additions and 240 deletions

View File

@ -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<ApiDocumentSimpleInfoDTO> list(@RequestBody ApiDocumentRequest request) {
List<ApiDocumentSimpleInfoDTO> returnList = apiDocumentService.findApiDocumentSimpleInfoByRequest(request);
public List<ApiDocumentInfoDTO> list(@RequestBody ApiDocumentRequest request) {
List<ApiDocumentInfoDTO> 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;
}
}

View File

@ -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;
}

View File

@ -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<String> apiIdList;
}

View File

@ -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;
}

View File

@ -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<String> shareApiIdList;
}

View File

@ -0,0 +1,5 @@
package io.metersphere.api.dto.document;
public enum ApiDocumentShareType {
Single,Batch
}

View File

@ -1,4 +1,4 @@
package io.metersphere.api.dto;
package io.metersphere.api.dto.document;
import lombok.Getter;
import lombok.Setter;

View File

@ -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<ApiDocumentSimpleInfoDTO> findApiDocumentSimpleInfoByRequest(ApiDocumentRequest request) {
return extApiDocumentMapper.findApiDocumentSimpleInfoByRequest(request);
public List<ApiDocumentInfoDTO> findApiDocumentSimpleInfoByRequest(ApiDocumentRequest request) {
if (this.isParamLegitimacy(request)) {
if (request.getProjectId() == null) {
List<String> shareIdList = this.selectShareIdByApiDocumentShareId(request.getShareId());
request.setApiIdList(shareIdList);
return extApiDocumentMapper.findApiDocumentSimpleInfoByRequest(request);
}else {
return extApiDocumentMapper.findApiDocumentSimpleInfoByRequest(request);
}
} else {
return new ArrayList<>();
}
}
private List<String> selectShareIdByApiDocumentShareId(String shareId) {
List<String> 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<Map<String, String>> 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<String, String> 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<Map<String, String>> 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<String, String> 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<Map<String, String>> 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<String, String> 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<Map<String, String>> 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<String, String> 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<ApiDocumentShare> 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<ApiDocumentShare> findByShareTypeAndShareApiIdWithBLOBs(String shareType, List<String> shareApiIdList) {
String shareApiIdString = this.genShareIdJsonString(shareApiIdList);
return extApiDocumentShareMapper.selectByShareTypeAndShareApiIdWithBLOBs(shareType,shareApiIdString);
}
/**
* 根据treeSet排序生成apiId的Jsonarray字符串
* @param shareApiIdList 要分享的ID集合
* @return 要分享的ID JSON格式字符串
*/
private String genShareIdJsonString(Collection<String> shareApiIdList) {
TreeSet<String> 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;
}
}

View File

@ -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;
}

View File

@ -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<Criteria> oredCriteria;
public ApiDocumentShareExample() {
oredCriteria = new ArrayList<Criteria>();
}
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<Criteria> 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<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<Criterion>();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
}
public List<Criterion> 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<String> values) {
addCriterion("id in", values, "id");
return (Criteria) this;
}
public Criteria andIdNotIn(List<String> 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<Long> values) {
addCriterion("create_time in", values, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotIn(List<Long> 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<String> values) {
addCriterion("create_user_id in", values, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdNotIn(List<String> 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<Long> values) {
addCriterion("update_time in", values, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeNotIn(List<Long> 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<String> values) {
addCriterion("share_type in", values, "shareType");
return (Criteria) this;
}
public Criteria andShareTypeNotIn(List<String> 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);
}
}
}

View File

@ -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<ApiDocumentShare> selectByExampleWithBLOBs(ApiDocumentShareExample example);
List<ApiDocumentShare> 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);
}

View File

@ -0,0 +1,270 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.base.mapper.ApiDocumentShareMapper">
<resultMap id="BaseResultMap" type="io.metersphere.base.domain.ApiDocumentShare">
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="create_user_id" jdbcType="VARCHAR" property="createUserId" />
<result column="update_time" jdbcType="BIGINT" property="updateTime" />
<result column="share_type" jdbcType="VARCHAR" property="shareType" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.ApiDocumentShare">
<result column="share_api_id" jdbcType="LONGVARCHAR" property="shareApiId" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, create_time, create_user_id, update_time, share_type
</sql>
<sql id="Blob_Column_List">
share_api_id
</sql>
<select id="selectByExampleWithBLOBs" parameterType="io.metersphere.base.domain.ApiDocumentShareExample" resultMap="ResultMapWithBLOBs">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from api_document_share
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByExample" parameterType="io.metersphere.base.domain.ApiDocumentShareExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from api_document_share
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="ResultMapWithBLOBs">
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from api_document_share
where id = #{id,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete from api_document_share
where id = #{id,jdbcType=VARCHAR}
</delete>
<delete id="deleteByExample" parameterType="io.metersphere.base.domain.ApiDocumentShareExample">
delete from api_document_share
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="io.metersphere.base.domain.ApiDocumentShare">
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>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.ApiDocumentShare">
insert into api_document_share
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="createUserId != null">
create_user_id,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="shareType != null">
share_type,
</if>
<if test="shareApiId != null">
share_api_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=BIGINT},
</if>
<if test="createUserId != null">
#{createUserId,jdbcType=VARCHAR},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=BIGINT},
</if>
<if test="shareType != null">
#{shareType,jdbcType=VARCHAR},
</if>
<if test="shareApiId != null">
#{shareApiId,jdbcType=LONGVARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.metersphere.base.domain.ApiDocumentShareExample" resultType="java.lang.Long">
select count(*) from api_document_share
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update api_document_share
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=VARCHAR},
</if>
<if test="record.createTime != null">
create_time = #{record.createTime,jdbcType=BIGINT},
</if>
<if test="record.createUserId != null">
create_user_id = #{record.createUserId,jdbcType=VARCHAR},
</if>
<if test="record.updateTime != null">
update_time = #{record.updateTime,jdbcType=BIGINT},
</if>
<if test="record.shareType != null">
share_type = #{record.shareType,jdbcType=VARCHAR},
</if>
<if test="record.shareApiId != null">
share_api_id = #{record.shareApiId,jdbcType=LONGVARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExampleWithBLOBs" parameterType="map">
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}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
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}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="io.metersphere.base.domain.ApiDocumentShare">
update api_document_share
<set>
<if test="createTime != null">
create_time = #{createTime,jdbcType=BIGINT},
</if>
<if test="createUserId != null">
create_user_id = #{createUserId,jdbcType=VARCHAR},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=BIGINT},
</if>
<if test="shareType != null">
share_type = #{shareType,jdbcType=VARCHAR},
</if>
<if test="shareApiId != null">
share_api_id = #{shareApiId,jdbcType=LONGVARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKeyWithBLOBs" parameterType="io.metersphere.base.domain.ApiDocumentShare">
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>
<update id="updateByPrimaryKey" parameterType="io.metersphere.base.domain.ApiDocumentShare">
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}
</update>
</mapper>

View File

@ -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<ApiDocumentSimpleInfoDTO> findApiDocumentSimpleInfoByRequest(@Param("request") ApiDocumentRequest request);
List<ApiDocumentInfoDTO> findApiDocumentSimpleInfoByRequest(@Param("request") ApiDocumentRequest request);
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.base.mapper.ext.ExtApiDocumentMapper">
<select id="findApiDocumentSimpleInfoByRequest" resultType="io.metersphere.api.dto.ApiDocumentSimpleInfoDTO">
<select id="findApiDocumentSimpleInfoByRequest" resultType="io.metersphere.api.dto.document.ApiDocumentInfoDTO">
SELECT api.id,api.name FROM Api_definition api
<where>
<if test="request.projectId != null">
@ -13,13 +13,18 @@
<if test="request.type != null and request.type != '' and request.type != 'ALL' ">
AND api.method = #{request.type}
</if>
<if test="request.moduleIds != null and request.moduleIds.size() > 0">
AND api.module_id in
<foreach collection="request.moduleIds" item="nodeId" separator="," open="(" close=")">
#{nodeId}
</foreach>
</if>
<if test="request.apiIdList != null and request.apiIdList.size() > 0">
AND api.id in
<foreach collection="request.apiIdList" item="apiId" separator="," open="(" close=")">
#{apiId}
</foreach>
</if>
</where>
<if test="request.orderCondition == 'createTimeDesc'">
ORDER BY api.create_time DESC

View File

@ -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<ApiDocumentShare> selectByShareTypeAndShareApiIdWithBLOBs(@Param("shareType") String shareType, @Param("shareApiId") String shareApiIdString);
}

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.base.mapper.ext.ExtApiDocumentShareMapper">
<resultMap id="BaseResultMap" type="io.metersphere.base.domain.ApiDocumentShare">
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="create_user_id" jdbcType="VARCHAR" property="createUserId" />
<result column="update_time" jdbcType="BIGINT" property="updateTime" />
<result column="share_type" jdbcType="VARCHAR" property="shareType" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.ApiDocumentShare">
<result column="share_api_id" jdbcType="LONGVARCHAR" property="shareApiId" />
</resultMap>
<select id="selectByShareTypeAndShareApiIdWithBLOBs" resultMap="ResultMapWithBLOBs">
SELECT id,share_type,share_api_id FROM api_document_share
<where>
share_type = #{shareType} AND share_api_id = #{shareApiId}
</where>
</select>
</mapper>

View File

@ -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(){

View File

@ -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",

View File

@ -1,8 +1,8 @@
<template>
<div>
<el-container>
<el-main style="padding-top: 0px">
<el-row>
<el-main style="padding-top: 0px;padding-bottom: 0px">
<el-row style="margin-top: 10px">
<el-select size="small" :placeholder="$t('api_test.definition.document.order')" v-model="apiSearch.orderCondition" style="float: right;width: 180px;margin-right: 5px"
class="ms-api-header-select" @change="initApiDocSimpleList" clearable>
<el-option key="createTimeDesc" :label="$t('api_test.definition.document.create_time_sort')" value="createTimeDesc" />
@ -24,12 +24,25 @@
</el-select>
<el-input :placeholder="$t('api_test.definition.document.search_by_api_name')" @blur="initApiDocSimpleList()" style="float: right;width: 180px;margin-right: 5px" size="small"
@keyup.enter.native="initApiDocSimpleList()" v-model="apiSearch.name"/>
<api-document-batch-share v-xpack @shareApiDocument="shareApiDocument" :project-id="projectId" :share-url="batchShareUrl" style="float: right;margin: 6px;font-size: 17px"/>
</el-row>
<el-divider></el-divider>
<div ref="apiDocInfoDiv">
<div style="margin-bottom: 50px">
<div ref="apiDocInfoDiv" @scroll="handleScroll" >
<div v-for="(apiInfo) in apiInfoArray" :key="apiInfo.id" ref="apiDocInfoDivItem">
<div style="font-size: 17px">
<i class="el-icon-share"></i>{{ apiInfo.name }}
<el-popover
v-if="projectId"
placement="right"
width="260"
@show="shareApiDocument('false')">
<p>{{shareUrl}}</p>
<div style="text-align: right; margin: 0">
<el-button type="primary" size="mini"
v-clipboard:copy="shareUrl">{{ $t("commons.copy") }}</el-button>
</div>
<i class="el-icon-share" slot="reference" style="margin-right: 10px;cursor: pointer"></i>
</el-popover>
{{ apiInfo.name }}
<span class="apiStatusTag">
<api-status :value="apiInfo.status"/>
</span>
@ -54,7 +67,9 @@
<div class="blackFontClass">
{{ $t('api_test.definition.document.request_head') }}
<div v-if="getJsonArr(apiInfo.requestHead).length==0">
{{ $t('api_test.definition.document.data_set.none') }}
<div class="simpleFontClass" style="margin-top: 10px">
{{ $t('api_test.definition.document.data_set.none') }}
</div>
</div>
<div v-else>
<el-table border :show-header="false"
@ -74,7 +89,9 @@
<div class="blackFontClass">
URL{{ $t('api_test.definition.document.request_param') }}
<div v-if="getJsonArr(apiInfo.urlParams).length==0">
{{ $t('api_test.definition.document.data_set.none') }}
<div class="simpleFontClass" style="margin-top: 10px">
{{ $t('api_test.definition.document.data_set.none') }}
</div>
</div>
<div v-else>
<el-table border
@ -133,7 +150,7 @@
min-width="120px"
show-overflow-tooltip/>
</el-table>
<div v-else-if="apiInfo.requestBodyParamType == 'JSON-SCHEMA'">
<div v-else-if="apiInfo.requestBodyParamType == 'JSON-SCHEMA'" style="margin-left: 10px">
<ms-json-code-edit :body="apiInfo.jsonSchemaBody" ref="jsonCodeEdit"/>
</div>
<div v-else class="showDataDiv">
@ -247,7 +264,7 @@
<el-aside width="200px" style="margin-top: 70px;">
<div ref="apiDocList" >
<el-steps style="height: 40%" direction="vertical" :active="apiStepIndex">
<el-step v-for="(apiInfo) in apiSimpleInfoArray" :key="apiInfo.id" @click.native="clickStep(apiInfo.id)">
<el-step v-for="(apiInfo) in apiInfoArray" :key="apiInfo.id" @click.native="clickStep(apiInfo.id)">
<el-link slot="title">{{ apiInfo.name }}</el-link>
</el-step>
</el-steps>
@ -265,18 +282,25 @@ import {formatJson,} from "@/common/js/format-utils";
import ApiStatus from "@/business/components/api/definition/components/list/ApiStatus";
import {calculate} from "@/business/components/api/definition/model/ApiTestModel";
import MsJsonCodeEdit from "@/business/components/common/json-schema/JsonSchemaEditor";
import Api from "@/business/components/api/router";
const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/);
const apiDocumentBatchShare = requireComponent.keys().length > 0 ? requireComponent("./share/ApiDocumentBatchShare.vue") : {};
export default {
name: "ApiDocumentItem",
components: {
Api,
MsJsonCodeEdit,
MsAnchor, ApiStatus, MsCodeEdit,
"ApiDocumentBatchShare": apiDocumentBatchShare.default
},
data() {
return {
shareUrl:"",
batchShareUrl:"",
apiStepIndex: 0,
apiSimpleInfoArray: [],
apiInfoArray: [],
modes: ['text', 'json', 'xml', 'html'],
formParamTypes: ['form-data', 'x-www-from-urlencoded', 'BINARY'],
mockVariableFuncs: [],
@ -285,7 +309,8 @@ export default {
type:"ALL",
orderCondition:"createTimeDesc",
},
apiInfo: {
apiInfoBaseObj: {
selectedFlag:false,
method: "无",
uri: "无",
name: "无",
@ -295,6 +320,7 @@ export default {
requestBodyParamType: "无",
requestBodyFormData: '[]',
requestBodyStrutureData: "",
sharePopoverVisible:false,
jsonSchemaBody: {},
responseHead: "无",
responseBody: "",
@ -309,7 +335,9 @@ export default {
},
props: {
projectId: String,
documentId: String,
moduleIds: Array,
pageHeaderHeight:Number,
},
activated() {
this.initApiDocSimpleList();
@ -327,27 +355,21 @@ export default {
window.onresize = function () {
this.clientHeight = `${document.documentElement.clientHeight}`;
this.changeFixed(this.clientHeight);
}
};
window.addEventListener('scroll',that.handleScroll);
},
mounted() {
let that = this;
window.onresize = function () {
this.clientHeight = `${document.documentElement.clientHeight}`;
if (that.$refs.apiDocInfoDiv) {
that.$refs.apiDocInfoDiv.style.minHeight = this.clientHeight - 300 + 'px';
that.$refs.apiDocList.style.minHeight = this.clientHeight - 300 + 'px';
}
}
that.clientHeight = `${document.documentElement.clientHeight}`;
that.changeFixed(that.clientHeight);
};
// handleScroll
window.addEventListener('scroll',this.handleScroll);
},
computed: {
documentId: function () {
return this.$route.params.documentId;
}
},
watch: {
'$route.params.documentId'() {
},
moduleIds() {
this.initApiDocSimpleList();
},
@ -365,10 +387,14 @@ export default {
},
changeFixed(clientHeight) {
if (this.$refs.apiDocInfoDiv) {
this.$refs.apiDocInfoDiv.style.height = clientHeight - 350 + 'px';
this.$refs.apiDocInfoDiv.style.overflow = 'auto';
this.$refs.apiDocList.style.height = clientHeight - 350 + 'px';
let countPageHeight = 350;
if(this.pageHeaderHeight!=0 && this.pageHeaderHeight != null){
countPageHeight = this.pageHeaderHeight
}
this.$refs.apiDocInfoDiv.style.height = clientHeight - countPageHeight + 'px';
this.$refs.apiDocInfoDiv.style.overflow = 'auto';
this.$refs.apiDocList.style.height = clientHeight - countPageHeight + 'px';
}
},
initApiDocSimpleList() {
@ -377,36 +403,71 @@ export default {
simpleRequest.projectId = this.projectId;
}
if (this.documentId != null && this.documentId != "") {
simpleRequest.documentId = this.documentId;
simpleRequest.shareId = this.documentId;
}
if (this.moduleIds.length > 0) {
simpleRequest.moduleIds = this.moduleIds;
}
let simpleInfoUrl = "/api/document/selectApiSimpleInfo";
this.apiSimpleInfoArray = [];
this.apiInfoArray = [];
this.$post(simpleInfoUrl, simpleRequest, response => {
this.apiSimpleInfoArray = response.data;
this.apiInfoArray = response.data;
this.apiStepIndex = 0;
if (this.apiSimpleInfoArray.length > 0) {
this.selectApiInfo(this.apiSimpleInfoArray[0].id);
if (this.apiInfoArray.length > 0) {
this.checkApiInfoNode(this.apiStepIndex);
}
});
},
selectApiInfo(apiId) {
shareApiDocument(isBatchShare){
let thisHost = window.location.host;
this.shareUrl = "";
this.batchShareUrl = "";
let shareIdArr = [];
let shareType = "Single";
if(isBatchShare == 'true'){
this.apiInfoArray.forEach(f => {
if (!f.id) {
return;
}
shareIdArr.push(f.id);
});
shareType = "Batch";
}else{
shareIdArr.push(this.apiInfoArray[this.apiStepIndex].id);
}
let genShareInfoParam = {};
genShareInfoParam.shareApiIdList = shareIdArr;
genShareInfoParam.shareType = shareType;
this.$post("/api/document/generateApiDocumentShareInfo", genShareInfoParam, res => {
if(shareType == "Batch"){
this.batchShareUrl = "http://"+thisHost+"/document"+res.data.shareUrl;
}else{
this.shareUrl = "http://"+thisHost+"/document"+res.data.shareUrl;
}
}, (error) => {
});
},
selectApiInfo(index,apiId) {
let simpleInfoUrl = "/api/document/selectApiInfoById/" + apiId;
this.$get(simpleInfoUrl, response => {
this.apiInfo = response.data;
//this.apiInfoObj = response.data;
//this.apiInfoArray.push(response.data);
this.$set(this.apiInfoArray,index,response.data);
});
},
clickStep(apiId) {
for (let index = 0; index < this.apiSimpleInfoArray.length; index++) {
if (apiId == this.apiSimpleInfoArray[index].id) {
for (let index = 0; index < this.apiInfoArray.length; index++) {
if (apiId == this.apiInfoArray[index].id) {
this.apiStepIndex = index;
break;
}
}
this.selectApiInfo(apiId);
//
this.checkApiInfoNode(this.apiStepIndex);
//
this.redirectScroll(this.apiStepIndex);
},
stepClick(stepIndex) {
this.apiStepIndex = stepIndex;
@ -422,11 +483,10 @@ export default {
ret = "否"
}
return ret;
},
getJsonArr(jsonString) {
let returnJsonArr = [];
if (jsonString == '无') {
if (jsonString == '无' || jsonString == null) {
return returnJsonArr;
}
@ -447,8 +507,10 @@ export default {
for (var key in previewData) {
// showDataObj.set(key,previewData[key]);
let value = previewData[key];
if (value.indexOf("@") >= 0) {
value = this.showPreview(value);
if(typeof(value)=='string'){
if (value.indexOf("@") >= 0) {
value = this.showPreview(value);
}
}
showDataObj[key] = value;
}
@ -480,13 +542,89 @@ export default {
itemValue = calculate(itemValue);
return itemValue;
},
onCopySuccess: function (e) {
if(this.apiStepIndex < this.apiInfoArray.length){
this.apiInfoArray[this.apiStepIndex].sharePopoverVisible = false;
}
this.$message({
message: this.$t('commons.copy_success'),
type: 'success'
});
},
onCopyError: function (e) {
if(this.apiStepIndex < this.apiInfoArray.length){
this.apiInfoArray[this.apiStepIndex].sharePopoverVisible = false;
}
this.$message.error(this.$t('api_report.error'));
},
handleScroll(){
// let itemHeight = 0;
// if(this.$refs.apiDocInfoDivItem.length>0){
// // item+20(20margin)
// itemHeight = this.$refs.apiDocInfoDivItem[0].offsetHeight+20;
// }
//apiDocInfoDiv(item+20)
let apiDocDivScrollTop = this.$refs.apiDocInfoDiv.scrollTop;
let apiDocDivClientTop = this.$refs.apiDocInfoDiv.clientHeight;
let scrolledHeigh = apiDocDivScrollTop+apiDocDivClientTop;
let lastIndex = 0;
for (let index = 0; index < this.apiInfoArray.length; index++) {
//. : +-index(20px)>0 index
if(scrolledHeigh>0){
lastIndex = index;
let itemHeight = this.$refs.apiDocInfoDivItem[index].offsetHeight+20;
scrolledHeigh = scrolledHeigh - itemHeight;
}else{
break;
}
}
this.apiStepIndex = lastIndex;
// 3
this.checkApiInfoNode(this.apiStepIndex);
},
redirectScroll(itemIndex){
//api
// let apiDocDivClientTop = this.$refs.apiDocInfoDiv.clientHeight;
let apiDocDivClientTop = 0;
let itemHeightCount = 0;
for (let i = 0; i <= itemIndex-1; i++) {
let itemHeight = this.$refs.apiDocInfoDivItem[i].offsetHeight+20;
itemHeightCount+=itemHeight;
}
this.$refs.apiDocInfoDiv.scrollTop = (apiDocDivClientTop+itemHeightCount);
},
checkApiInfoNode(itemIndex){
//api3
let beforeNodeIndex = itemIndex<3?0:(itemIndex-3);
let afterNodeIndex = (itemIndex+3)<this.apiInfoArray.length?(itemIndex+3):this.apiInfoArray.length;
for(let i = itemIndex;i < afterNodeIndex;i++){
let apiInfo = this.apiInfoArray[i];
if(apiInfo == null || !apiInfo.selectedFlag){
let apiId = apiInfo.id;
this.selectApiInfo(i,apiId);
}
}
for(let i = beforeNodeIndex;i <itemIndex;i++){
let apiInfo = this.apiInfoArray[i];
if(apiInfo == null || !apiInfo.selectedFlag){
let apiId = apiInfo.id;
this.selectApiInfo(i,apiId);
}
}
}
},
}
</script>
<style scoped>
.simpleFontClass {
font-weight: normal;
font-size: 14px;
margin-left: 10px;
}
.blackFontClass {
@ -496,7 +634,7 @@ export default {
.smallFontClass {
font-size: 13px;
margin: 20px 0px;
margin: 20px 10px;
}
.tip {
@ -516,7 +654,7 @@ export default {
.showDataDiv {
background-color: #F5F7F9;
margin: 20px 0px;
margin: 20px 10px;
}
/*

View File

@ -0,0 +1,66 @@
<template>
<div>
<div class="questionList-content-list">
</div>
</div>
</template>
<script>
export default {
name: "TestScroll",
components: {
},
data() {
return {
seeThis:0,
tabs:['tab0','tab1','tab2'],
}
},
props: {
projectId: String,
documentId: String,
moduleIds: Array,
pageHeaderHeight:Number,
},
activated() {
},
created () {
window.addEventListener('scroll',this.handleScroll)
},
mounted() {
},
computed: {
},
watch: {
},
methods: {
goAnchor(index) { // scrollIntoView
// document.querySelector('#anchor'+index).scrollIntoView()
this.seeThis = index; var anchor = this.$el.querySelector('#anchor'+index)
document.body.scrollTop = anchor.offsetTop-100
document.documentElement.scrollTop = anchor.offsetTop-100
},
handleScroll(){
let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop //
let offsetTop = document.querySelector('#boxFixed').offsetTop; //
var anchorOffset0 = this.$el.querySelector('#anchor0').offsetTop-100
var anchorOffset1 = this.$el.querySelector('#anchor1').offsetTop-100
var anchorOffset2 = this.$el.querySelector('#anchor2').offsetTop-100
if(scrollTop>anchorOffset0&&scrollTop<anchorOffset1){
this.seeThis = 0
}
if(scrollTop>anchorOffset1&&scrollTop<anchorOffset2){
this.seeThis = 1
}
if(scrollTop>anchorOffset2){
this.seeThis = 2
}
},
},
}
</script>
<style scoped>
</style>

View File

@ -21,6 +21,7 @@ import VueFab from 'vue-float-action-button'
import {left2RightDrag, bottom2TopDrag, right2LeftDrag} from "../common/js/directive";
import JsonSchemaEditor from './components/common/json-schema/schema/index';
import JSONPathPicker from 'vue-jsonpath-picker';
import VueClipboard from 'vue-clipboard2'
Vue.use(JsonSchemaEditor);
import VuePapaParse from 'vue-papa-parse'
@ -40,6 +41,7 @@ Vue.use(CKEditor);
Vue.use(YanProgress);
Vue.use(VueFab);
Vue.use(JSONPathPicker);
Vue.use(VueClipboard)
// v-permission
Vue.directive('permission', permission);

View File

@ -0,0 +1,62 @@
<template>
<div>
<api-document-item :pageHeaderHeight="pageHeaderHeight" :project-id="projectId" :module-ids="moduleIds" :document-id="documentId" ref="apiDocumentItem"/>
<!-- <test-scroll></test-scroll>-->
</div>
</template>
<script>
import ApiDocumentItem from "@/business/components/api/definition/components/document/ApiDocumentItem";
import TestScroll from "@/business/components/api/definition/components/document/TestScroll";
export default {
name: "ApiDocumentsPage",
components: {
TestScroll,
ApiDocumentItem,
},
data() {
return {
documentId:"",
projectId:"",
pageHeaderHeight:100,
moduleIds:[],
}
},
props: {
activeDom:String,
isApiListEnable: {
type: Boolean,
default: false,
},
},
created: function () {
this.selectDocumentInfo();
},
watch: {
},
computed: {
},
methods: {
getUrlParam(){
let queryParams =this.$route.query;
let documentIdParam = queryParams['documentId'];
this.documentId = queryParams['documentId'];
return documentIdParam;
},
selectDocumentInfo(){
this.getUrlParam();
if(this.$refs.apiDocumentItem){
this.$refs.apiDocumentItem.initApiDocSimpleList();
}
}
},
}
</script>
<style scoped>
</style>

View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="shortcut icon" href="<%= BASE_URL %>favicon.ico">
<title>MeterSphere Api Document</title>
</head>
<body>
<div id="document"></div>
</body>
</html>

View File

@ -0,0 +1,34 @@
import Vue from 'vue';
import ElementUI, {Button, Col, Form, FormItem, Input, Row} from 'element-ui';
import '../assets/theme/index.css';
import '../common/css/menu-header.css';
import '../common/css/main.css';
import Document from "./Document.vue";
import Ajax from "@/common/js/ajax";
import i18n from "@/i18n/i18n";
import router from "@/business/components/common/router/router";
import JsonSchemaEditor from "@/business/components/common/json-schema/schema/index";
import JSONPathPicker from 'vue-jsonpath-picker';
Vue.use(JsonSchemaEditor);
import VuePapaParse from 'vue-papa-parse'
Vue.use(VuePapaParse)
Vue.use(ElementUI, {
i18n: (key, value) => i18n.t(key, value)
});
Vue.use(Row);
Vue.use(Col);
Vue.use(Form);
Vue.use(FormItem);
Vue.use(Input);
Vue.use(Button);
Vue.use(Ajax);
Vue.use(JSONPathPicker);
new Vue({
el: '#document',
router,
i18n,
render: h => h(Document)
});

View File

@ -9,10 +9,12 @@ module.exports = {
devServer: {
port: 8080,
proxy: {
['^(?!/login)']: {
//1.8需求:增加分享功能,不登陆即可看到文档页面。所以代理设置增加了(?!/document)文档页面的相关信息
// ['^((?!/login)']: {
['^((?!/login)(?!/document))']: {
target: 'http://localhost:8081',
ws: true,
}
},
}
},
pages: {
@ -25,6 +27,11 @@ module.exports = {
entry: "src/login/login.js",
template: "src/login/login.html",
filename: "login.html"
},
document: {
entry: "src/document/document.js",
template: "src/document/document.html",
filename: "document.html"
}
},
configureWebpack: {