fix: 修复Mock服务下JsonSchema参数返回格式没被处理的问题
修复Mock服务下JsonSchema参数返回格式没被处理的问题
This commit is contained in:
parent
8412d77c97
commit
7727610c2e
|
@ -0,0 +1,36 @@
|
|||
package io.metersphere.api.dto.mockconfig.response;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* @author song.tianyang
|
||||
* @Date 2021/4/30 3:11 下午
|
||||
* @Description
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class JsonSchemaReturnObj {
|
||||
private mockObj mock;
|
||||
private int minLength = -1;
|
||||
private String pattern;
|
||||
private String format;
|
||||
private String description;
|
||||
private String title;
|
||||
private String type;
|
||||
private int maxLength = -1;
|
||||
|
||||
public String getMockValue() {
|
||||
if (mock == null) {
|
||||
return "";
|
||||
} else {
|
||||
return mock.mock;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
class mockObj {
|
||||
String mock;
|
||||
}
|
|
@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.metersphere.api.dto.mockconfig.MockConfigRequest;
|
||||
import io.metersphere.api.dto.mockconfig.MockExpectConfigRequest;
|
||||
import io.metersphere.api.dto.mockconfig.response.JsonSchemaReturnObj;
|
||||
import io.metersphere.api.dto.mockconfig.response.MockConfigResponse;
|
||||
import io.metersphere.api.dto.mockconfig.response.MockExpectConfigResponse;
|
||||
import io.metersphere.base.domain.*;
|
||||
|
@ -324,7 +325,18 @@ public class MockConfigService {
|
|||
}
|
||||
if (isJsonSchema) {
|
||||
if (bodyObj.containsKey("jsonSchema") && bodyObj.getJSONObject("jsonSchema").containsKey("properties")) {
|
||||
returnStr = bodyObj.getJSONObject("jsonSchema").getJSONObject("properties").toJSONString();
|
||||
String bodyRetunStr = bodyObj.getJSONObject("jsonSchema").getJSONObject("properties").toJSONString();
|
||||
JSONObject bodyReturnObj = JSONObject.parseObject(bodyRetunStr);
|
||||
Set<String> keySet = bodyReturnObj.keySet();
|
||||
JSONObject returnObj = new JSONObject();
|
||||
for (String key : keySet) {
|
||||
try {
|
||||
JsonSchemaReturnObj obj = bodyReturnObj.getObject(key, JsonSchemaReturnObj.class);
|
||||
returnObj.put(key, obj.getMockValue());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
returnStr = returnObj.toJSONString();
|
||||
}
|
||||
} else {
|
||||
if (bodyObj.containsKey("raw")) {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<div class="ms-border">
|
||||
<el-form-item prop="socket">
|
||||
<span class="ms-env-span">{{$t('api_test.environment.socket')}}</span>
|
||||
<el-input v-model="condition.socket" style="width: 80%" :placeholder="$t('api_test.request.url_description')" clearable size="small" :disabled="httpConfig.isMock">
|
||||
<el-input v-model="condition.socket" style="width: 80%" :placeholder="$t('api_test.request.url_description')" clearable size="small">
|
||||
<template slot="prepend">
|
||||
<el-select v-model="condition.protocol" class="request-protocol-select" size="small">
|
||||
<el-option label="http://" value="http"/>
|
||||
|
@ -69,9 +69,9 @@
|
|||
</el-table-column>
|
||||
<el-table-column :label="$t('commons.operating')" width="100px">
|
||||
<template v-slot:default="{row}">
|
||||
<ms-table-operator-button :disabled="httpConfig.isMock" :tip="$t('api_test.automation.copy')"
|
||||
<ms-table-operator-button :tip="$t('api_test.automation.copy')"
|
||||
icon="el-icon-document-copy" @exec="copy(row)"/>
|
||||
<ms-table-operator-button :disabled="httpConfig.isMock" :tip="$t('api_test.automation.remove')"
|
||||
<ms-table-operator-button :tip="$t('api_test.automation.remove')"
|
||||
icon="el-icon-delete" @exec="remove(row)" type="danger" v-tester/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
|
Loading…
Reference in New Issue