Feature: Test Karate schema validation
Scenario: Test nested json objects
* def response = read('tasks.json')
* def schema = { ab: "##[] string", c: "##[] string" }
* match response ==
"""
{
id: '#string',
name: '#string',
obj1: '#(schema)' ,
obj2: '##(schema)' ,
obj3: '#(schema)' ,
obj4: '#null'
}
"""
以下是使用的json文件 (任务.json)
{
"id": "ad:p2:53456:4634:yu",
"name": "name",
"obj1": {
"ab": [
"test"
],
"c": null
},
"obj2": null,
"obj3": {
"ab": [
"tester"
],
"c": [
"t1", "t2"
]
},
"obj4": null
}
错误:com.intuit.karate.exception.KarateException:javascript 评估失败:字符串,ReferenceError:“字符串”未在第 1 行定义
我尝试过多种方法,例如:
obj1: '#(^模式)',
obj1: '#对象架构'
但无法解决问题。