空手道嵌套JSON对象模式验证导致空手道异常 [英] Karate - Nested JSON object schema validation causes KarateException

查看:18
本文介绍了空手道嵌套JSON对象模式验证导致空手道异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.tuit.karate.Exeption.KarateException:JavaScript求值失败:字符串,未在第1行定义ReferenceError:&Quot;String&Quot;

我尝试了多种方法,例如: Obj1:‘#(^架构)’, Obj1:‘#对象架构’

但无法修复该问题。

推荐答案

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

这篇关于空手道嵌套JSON对象模式验证导致空手道异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆