fix(接口测试): 修复8000行JSON作为参数的接口使用文档无法加载的缺陷

修复8000行JSON作为参数的接口使用文档无法加载的缺陷
This commit is contained in:
song-tianyang 2022-04-02 23:18:41 +08:00 committed by CountryBuilder
parent b2b2e50b57
commit a0439bf844
4 changed files with 53 additions and 65 deletions

View File

@ -31,7 +31,7 @@ public class ApiDocumentInfoDTO {
private String requestBodyFormData;
private String requestBodyStrutureData;
private Object requestPreviewData;
private Object jsonSchemaBody;
private String jsonSchemaBody;
private String responseHead;
private String responseBody;

View File

@ -3,6 +3,7 @@ package io.metersphere.api.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import io.metersphere.api.dto.automation.APIScenarioReportResult;
import io.metersphere.api.dto.share.*;
import io.metersphere.base.domain.*;
@ -165,6 +166,7 @@ public class ShareInfoService {
}
}
} catch (Exception e) {
LogUtil.error(e.getMessage());
}
}
//rest参数设置
@ -180,6 +182,7 @@ public class ShareInfoService {
}
}
} catch (Exception e) {
LogUtil.error(e.getMessage());
}
}
apiInfoDTO.setUrlParams(urlParamArr.toJSONString());
@ -207,21 +210,13 @@ public class ShareInfoService {
isJsonSchema = true;
}
}
if (isJsonSchema) {
apiInfoDTO.setRequestBodyParamType("JSON-SCHEMA");
apiInfoDTO.setJsonSchemaBody(bodyObj);
if (bodyObj.containsKey("jsonSchema")) {
JSONObject jsonSchemaObj = bodyObj.getJSONObject("jsonSchema");
apiInfoDTO.setRequestPreviewData(JSON.parse(JSONSchemaGenerator.getJson(jsonSchemaObj.toJSONString())));
}
} else {
if (bodyObj.containsKey("raw")) {
String raw = bodyObj.getString("raw");
apiInfoDTO.setJsonSchemaBody(raw);
apiInfoDTO.setRequestBodyStrutureData(raw);
//转化jsonObje 或者 jsonArray
this.setPreviewData(previewJsonArray, raw);
}
}
} else if (StringUtils.equalsAny(type, "XML", "Raw")) {
if (bodyObj.containsKey("raw")) {
String raw = bodyObj.getString("raw");
@ -281,9 +276,8 @@ public class ShareInfoService {
}
}
} catch (Exception e) {
LogUtil.error(e.getMessage());
}
}
}
}
@ -303,7 +297,7 @@ public class ShareInfoService {
}
apiInfoDTO.setResponseHead(responseHeadDataArr.toJSONString());
} catch (Exception e) {
LogUtil.error(e.getMessage());
}
}
// 赋值响应体
@ -330,10 +324,8 @@ public class ShareInfoService {
}
}
if (isJsonSchema) {
// apiInfoDTO.setRequestBodyParamType("JSON-SCHEMA");
apiInfoDTO.setResponseBodyParamType("JSON-SCHEMA");
apiInfoDTO.setJsonSchemaResponseBody(bodyObj);
// apiInfoDTO.setJsonSchemaBody(bodyObj);
} else {
if (bodyObj.containsKey("raw")) {
String raw = bodyObj.getString("raw");
@ -342,10 +334,6 @@ public class ShareInfoService {
this.setPreviewData(previewJsonArray, raw);
}
}
// if (bodyObj.containsKey("raw")) {
// String raw = bodyObj.getString("raw");
// apiInfoDTO.setResponseBodyStrutureData(raw);
// }
} else if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) {
if (bodyObj.containsKey("kvs")) {
JSONArray bodyParamArr = new JSONArray();
@ -386,7 +374,7 @@ public class ShareInfoService {
}
}
} catch (Exception e) {
LogUtil.error(e.getMessage());
}
}
@ -403,7 +391,7 @@ public class ShareInfoService {
}
apiInfoDTO.setResponseCode(responseStatusDataArr.toJSONString());
} catch (Exception e) {
LogUtil.error(e.getMessage());
}
}
}
@ -418,21 +406,24 @@ public class ShareInfoService {
private JSONObject genJSONObject(String request) {
JSONObject returnObj = null;
try {
returnObj = JSONObject.parseObject(request);
returnObj = JSONObject.parseObject(request, Feature.DisableCircularReferenceDetect);
} catch (Exception e) {
LogUtil.error(e.getMessage());
}
return returnObj;
}
private void setPreviewData(JSONArray previewArray, String data) {
try {
JSONObject previewObj = JSONObject.parseObject(data);
JSONObject previewObj = JSONObject.parseObject(data, Feature.DisableCircularReferenceDetect);
previewArray.add(previewObj);
} catch (Exception e) {
LogUtil.error(e.getMessage());
}
try {
previewArray = JSONArray.parseArray(data);
} catch (Exception e) {
LogUtil.error(e.getMessage());
}
}
@ -571,16 +562,14 @@ public class ShareInfoService {
TestPlanWithBLOBs testPlan = getTestPlan(shareInfo);
if (testPlan != null) {
projectId = testPlan.getProjectId();
};
}
}
if (shareInfo.getShareType().equals("API_REPORT")) {
type = ProjectApplicationType.API_SHARE_REPORT_TIME.toString();
APIScenarioReportResult reportResult = extApiScenarioReportMapper.get(shareInfo.getCustomData());
if (reportResult != null) {
projectId = reportResult.getProjectId();
};
}
}
if (StringUtils.isBlank(type) || Strings.isBlank(projectId)) {
millisCheck(System.currentTimeMillis() - shareInfo.getUpdateTime(), 1000 * 60 * 60 * 24, shareInfo.getId());

View File

@ -332,6 +332,9 @@ export default {
for (let dataIndex = 0; dataIndex < returnDatas.length; dataIndex++) {
let index = indexArr[dataIndex];
let data = returnDatas[dataIndex];
if (data.jsonSchemaBody) {
data.jsonSchemaBody = {raw:data.jsonSchemaBody};
}
this.$set(this.apiInfoArray, index, data);
}
this.updateShowArray(itemIndex, afterNodeIndex, beforeNodeIndex);

View File

@ -27,14 +27,10 @@
min-width="120px"
show-overflow-tooltip/>
</el-table>
<div v-else-if="apiInfo.requestBodyParamType == 'JSON-SCHEMA'" style="margin-left: 10px">
<div v-else-if="apiInfo.requestBodyParamType === 'JSON-SCHEMA' || apiInfo.requestBodyParamType === 'JSON'" style="margin-left: 10px">
<ms-json-code-edit :show-preview="false" :json-schema-disable="true" :body="apiInfo.jsonSchemaBody"
ref="jsonCodeEdit"/>
</div>
<div v-else-if="formatRowDataToJsonSchema(apiInfo,'request') " style="margin-left: 10px">
<ms-json-code-edit :show-preview="false" :json-schema-disable="true" :body="apiInfo.requestJsonSchema"
ref="jsonCodeEdit"/>
</div>
<div v-else class="showDataDiv">
<br/>
<p style="margin: 0px 20px;"