refactor(接口测试): 优化大文件JSON转Schema格式卡顿现象
--bug=1011847 --user=赵勇 【接口测试】json太大,导入到接口定义和作为请求体发送会报错 https://www.tapd.cn/55049933/s/1128606
This commit is contained in:
parent
d18b3eaf3a
commit
8c35d73a39
|
@ -723,7 +723,7 @@ public class JmeterDefinitionParser extends ApiImportAbstractParser<ApiDefinitio
|
|||
if (CollectionUtils.isNotEmpty(headers)) {
|
||||
for (KeyValue header : headers) {
|
||||
if (StringUtils.equals(header.getName(), "Content-Type") && StringUtils.equals(header.getValue(), "application/json")) {
|
||||
samplerProxy.getBody().setType(Body.JSON);
|
||||
samplerProxy.getBody().setType(Body.JSON_STR);
|
||||
jsonType = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -204,7 +204,7 @@ public class Swagger2Parser extends SwaggerAbstractParser {
|
|||
|
||||
private String getBodyType(Operation operation) {
|
||||
if (CollectionUtils.isEmpty(operation.getConsumes())) {
|
||||
return Body.JSON;
|
||||
return Body.JSON_STR;
|
||||
}
|
||||
String contentType = operation.getConsumes().get(0);
|
||||
return getBodyType(contentType);
|
||||
|
@ -212,7 +212,7 @@ public class Swagger2Parser extends SwaggerAbstractParser {
|
|||
|
||||
private String getResponseBodyType(Operation operation) {
|
||||
if (CollectionUtils.isEmpty(operation.getProduces())) {
|
||||
return Body.JSON;
|
||||
return Body.JSON_STR;
|
||||
}
|
||||
String contentType = operation.getProduces().get(0);
|
||||
return getBodyType(contentType);
|
||||
|
@ -355,7 +355,7 @@ public class Swagger2Parser extends SwaggerAbstractParser {
|
|||
|
||||
private void parseRequestBodyParameters(Parameter parameter, Body body) {
|
||||
BodyParameter bodyParameter = (BodyParameter) parameter;
|
||||
if (body.getType().equals(Body.JSON)) {
|
||||
if (body.getType().equals(Body.JSON_STR)) {
|
||||
body.setJsonSchema(parseSchema2JsonSchema(bodyParameter.getSchema()));
|
||||
body.setFormat("JSON-SCHEMA");
|
||||
} else {
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package io.metersphere.api.dto.scenario;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import io.metersphere.api.dto.scenario.request.BodyFile;
|
||||
import io.metersphere.commons.json.JSONSchemaRunTest;
|
||||
import io.metersphere.commons.utils.FileUtils;
|
||||
import io.metersphere.jmeter.utils.ScriptEngineUtils;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -32,7 +34,7 @@ public class Body {
|
|||
public final static String WWW_FROM = "WWW_FORM";
|
||||
public final static String RAW = "Raw";
|
||||
public final static String BINARY = "BINARY";
|
||||
public final static String JSON = "JSON";
|
||||
public final static String JSON_STR = "JSON";
|
||||
public final static String XML = "XML";
|
||||
|
||||
public boolean isValid() {
|
||||
|
@ -90,13 +92,18 @@ public class Body {
|
|||
if (StringUtils.isNotBlank(this.type) && StringUtils.equals(this.type, "JSON")) {
|
||||
if (StringUtils.isNotEmpty(this.format) && this.getJsonSchema() != null
|
||||
&& "JSON-SCHEMA".equals(this.format)) {
|
||||
this.raw = JSONSchemaRunTest.getJson(com.alibaba.fastjson.JSON.toJSONString(this.getJsonSchema()));
|
||||
} else { // json 文本也支持 mock 参数
|
||||
this.raw = JSONSchemaRunTest.getJson(JSON.toJSONString(this.getJsonSchema()));
|
||||
} else {
|
||||
try {
|
||||
JSONObject jsonObject = com.alibaba.fastjson.JSON.parseObject(this.getRaw());
|
||||
if (StringUtils.isNotEmpty(this.getRaw())) {
|
||||
String jsonString = JSON.toJSONString(this.getRaw(), SerializerFeature.DisableCircularReferenceDetect);
|
||||
JSONObject jsonObject = JSON.parseObject(jsonString);
|
||||
jsonMockParse(jsonObject);
|
||||
this.raw = JSONObject.toJSONString(jsonObject, SerializerFeature.WriteMapNullValue);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LoggerUtil.error("json mock value is abnormal", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -157,7 +164,7 @@ public class Body {
|
|||
}
|
||||
|
||||
public boolean isJson() {
|
||||
return StringUtils.equals(type, JSON);
|
||||
return StringUtils.equals(type, JSON_STR);
|
||||
}
|
||||
|
||||
public boolean isXml() {
|
||||
|
|
|
@ -75,7 +75,7 @@ public abstract class ApiImportAbstractParser<T> implements ApiImportParser<T> {
|
|||
bodyType = Body.FORM_DATA;
|
||||
break;
|
||||
case "application/json":
|
||||
bodyType = Body.JSON;
|
||||
bodyType = Body.JSON_STR;
|
||||
break;
|
||||
case "application/xml":
|
||||
bodyType = Body.XML;
|
||||
|
@ -96,7 +96,7 @@ public abstract class ApiImportAbstractParser<T> implements ApiImportParser<T> {
|
|||
case Body.WWW_FROM:
|
||||
contentType = "application/x-www-form-urlencoded";
|
||||
break;
|
||||
case Body.JSON:
|
||||
case Body.JSON_STR:
|
||||
contentType = "application/json";
|
||||
break;
|
||||
case Body.XML:
|
||||
|
|
|
@ -200,7 +200,7 @@ public abstract class HarScenarioAbstractParser<T> extends ApiImportAbstractPars
|
|||
String bodyType = "";
|
||||
switch (raw.getString("language")) {
|
||||
case "json":
|
||||
bodyType = Body.JSON;
|
||||
bodyType = Body.JSON_STR;
|
||||
break;
|
||||
case "xml":
|
||||
bodyType = Body.XML;
|
||||
|
|
|
@ -155,7 +155,7 @@ public abstract class PostmanAbstractParserParser<T> extends ApiImportAbstractPa
|
|||
String bodyType = "";
|
||||
switch (raw.getString("language")) {
|
||||
case "json":
|
||||
bodyType = Body.JSON;
|
||||
bodyType = Body.JSON_STR;
|
||||
break;
|
||||
case "xml":
|
||||
bodyType = Body.XML;
|
||||
|
|
|
@ -131,7 +131,7 @@ public class HistoricalDataUpgradeService {
|
|||
}
|
||||
if ("json".equals(request1.getBody().getFormat())) {
|
||||
if ("Raw".equals(request1.getBody().getType())) {
|
||||
request1.getBody().setType(Body.JSON);
|
||||
request1.getBody().setType(Body.JSON_STR);
|
||||
if (CollectionUtils.isEmpty(request1.getHeaders())) {
|
||||
List<KeyValue> headers = new LinkedList<>();
|
||||
headers.add(new KeyValue("Content-Type", "application/json"));
|
||||
|
|
|
@ -206,6 +206,7 @@ class Convert {
|
|||
let objectTemplate = {
|
||||
$id: $id,
|
||||
title: `The ${key} Schema`,
|
||||
hidden: true,
|
||||
mock: {
|
||||
"mock": value
|
||||
},
|
||||
|
|
|
@ -94,7 +94,6 @@
|
|||
return;
|
||||
}
|
||||
let jsonData = MsConvert.format(json5.parse(this.json));
|
||||
//let jsonData = GenerateSchema(json5.parse(this.json));
|
||||
this.$emit('jsonData', jsonData);
|
||||
} else {
|
||||
if (!this.checkIsJsonSchema(this.jsonSchema)) {
|
||||
|
|
|
@ -205,6 +205,11 @@ export default {
|
|||
customing: false
|
||||
}
|
||||
},
|
||||
created() {
|
||||
if (this.pickValue) {
|
||||
this.hidden = this.pickValue.hidden;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onInputName(e) {
|
||||
const val = e.target.value
|
||||
|
|
Loading…
Reference in New Issue