Karate - 嵌套 JSON 对象模式验证导致 KarateException

2023-12-13

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: '#对象架构'

但无法解决问题。


它应该是##[] #string,阅读文档:https://github.com/intuit/karate#schema-validation

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Karate - 嵌套 JSON 对象模式验证导致 KarateException 的相关文章

随机推荐