fix(接口测试): 修复文档结构number 类型校验失败问题

--bug=1010130 --user=赵勇 【接口测试】 github#10194,添加文档断言,检验字段类型,是否必填不准确。响应json数据中包含jsonArray对象中的字段值无法检验 https://www.tapd.cn/55049933/s/1102897
This commit is contained in:
fit2-zhao 2022-02-10 18:22:52 +08:00 committed by fit2-zhao
parent 4e3bca34c4
commit 248ffd1182
2 changed files with 4 additions and 30 deletions

View File

@ -17,7 +17,6 @@ import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Pattern;
public class JSONToDocumentUtils {
@ -37,11 +36,7 @@ public class JSONToDocumentUtils {
} else {
String type = BasicConstant.STRING;
if (value != null) {
if (isWholeNumber(value.toString())) {
type = BasicConstant.INTEGER;
} else if (isNumber(value.toString())) {
type = BasicConstant.NUMBER;
}
type = DocumentUtils.getType(value);
}
children.add(new DocumentElement("", type, value, null));
}
@ -64,13 +59,7 @@ public class JSONToDocumentUtils {
} else {
String type = BasicConstant.STRING;
if (value != null) {
if (isWholeNumber(value.toString())) {
type = BasicConstant.INTEGER;
} else if (isNumber(value.toString())) {
type = BasicConstant.NUMBER;
} else if (StringUtils.equalsIgnoreCase(DocumentUtils.getType(value), BasicConstant.BOOLEAN)) {
type = BasicConstant.BOOLEAN;
}
type = DocumentUtils.getType(value);
}
children.add(new DocumentElement(key, type, value, null));
}
@ -122,17 +111,6 @@ public class JSONToDocumentUtils {
}
}
public static boolean isNumber(String number) {
Pattern pattern = Pattern.compile("^-?\\d+(\\.\\d+)?$");
return StringUtils.isNotEmpty(number) && pattern.matcher(number).matches();
}
public static boolean isWholeNumber(String wholeNumber) {
Pattern pattern = Pattern.compile("[+-]?[0-9]+?");
return StringUtils.isNotEmpty(wholeNumber) && pattern.matcher(wholeNumber).matches();
}
/**
* 从指定节点开始,递归遍历所有子节点
*/
@ -142,11 +120,7 @@ public class JSONToDocumentUtils {
if (listElement.isEmpty()) {
String type = BasicConstant.STRING;
if (StringUtils.isNotEmpty(node.getTextTrim())) {
if (isWholeNumber(node.getText())) {
type = BasicConstant.INTEGER;
} else if (isNumber(node.getText())) {
type = BasicConstant.NUMBER;
}
type = DocumentUtils.getType(node.getTextTrim());
}
children.add(new DocumentElement(node.getName(), type, node.getTextTrim(), null));
}

View File

@ -131,7 +131,7 @@ export default {
{value: 'object', label: 'object'},
{value: 'array', label: 'array'},
{value: 'string', label: 'string'},
{value: 'int', label: 'int'},
{value: 'integer', label: 'integer'},
{value: 'number', label: 'number'},
{value: 'boolean', label: 'boolean'},
],