空手道 - 嵌套 JSON 对象模式验证导致 KarateException
Karate - Nested JSON object schema validation causes KarateException
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使用的文件 (tasks.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: '#(^schema)',
obj1: '#object schema'
但无法解决问题。
应该是##[] #string
,看文档:https://github.com/intuit/karate#schema-validation
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使用的文件 (tasks.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: '#(^schema)', obj1: '#object schema'
但无法解决问题。
应该是##[] #string
,看文档:https://github.com/intuit/karate#schema-validation