【发布时间】:2020-09-29 20:30:32
【问题描述】:
我正在使用架构验证来验证响应,值返回一个数字或“NA”,下面是响应和架构验证。
Response:
{
"ID": "ES123D74590Z",
"companyName": "ABC Corp",
"hourMs": 67890000000,
"date": "2020-06-09T00:00:00.000Z",
"scores": {
"AllScore": 61,
"MaxScore": 59,
"ScoreA": 75,
"ScoreB": "NA",
"ScoreC": 49,
"ScoreD": "NA"
},
"movement": {},
"amt": {}
}
Schema Assertion:
{
"ID": '#string',
"companyName": '#string',
"hourMs": '#number',
"date": '#regex[^\d\d\d\d-([0-9]{2})-([0-9]{2})(\T)([0-9]{3}):([0-9]{3}):([0-9]{3})\.[0-9]{3}\Z)$]',
"scores": {
"AllScore": '##number? _ >= 0 && _ <=100 || _ == "NA"',
"MaxScore": '##number? _ >= 0 && _ <=100 || _ == "NA"',
"ScoreA": '##number? _ >= 0 && _ <=100 || _ == "NA"',
"ScoreB": '##number? _ >= 0 && _ <=100 || _ == "NA"',
"ScoreC": '##number? _ >= 0 && _ <=100 || _ == "NA"',
"ScoreD": '##number? _ >= 0 && _ <=100 || _ == "NA"'
},
"movement": {},
"amt": {}
}
收到错误信息:
com.intuit.karate.exception.KarateException: score.feature:19 - path: $.scores.ScoreB, actual: 'NA', expected: '##number? _ >= 0 && _ <=100 || _ == "NA"', reason: not a number
如何更正匹配表达式?
【问题讨论】:
-
不完整的例子。尝试改善您的问题。不需要剪切和粘贴。让别人更容易理解
-
如果以上更新有用请告诉我
标签: karate