【问题标题】:Karate - Nested JSON object schema validation causes KarateException空手道 - 嵌套 JSON 对象架构验证导致空手道异常
【发布时间】:2020-09-30 16:48:47
【问题描述】:
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 架构'

但无法解决问题。

【问题讨论】:

标签: karate


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-21
    • 1970-01-01
    • 2019-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-05
    • 1970-01-01
    相关资源
    最近更新 更多