所有键值都不匹配jsonschema

时间:2019-02-04 03:01:23

标签: karate

我下面有这样的jsonschema:

{
    "id": 0,
    "rc": "51",
    "product": {
        "code": "28",
        "label": "PLN",
        "type": "electricity",
        "ops": "PLN",
        "nominal": 50000
    },
    "cust_id": "01428800200",
    "order_id": "",
    "ref_no": "2033930693200733",
    "amount": 50000,
    "price": 50000,
    "created": -62135596800
}

这是我的模式验证

{
  "id": "#number",
  "rc": "#string",
  "product": {
    "code": "#string",
    "label": "#string",
    "type": "#string",
    "ops": "#string",
    "nominal": "#number"
  },
  "cust_id": "#string",
  "order_id": "#string",
  "ref_no": "#string",
  "amount": "#number",
  "price": "#number",
  "created": "#number? _ < 0"
}

但是我收到消息reason: all key-values did not match,但是我认为我的模式是正确的,因此有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

这对我有用,您的脚本中必须有一些错误。将以下内容粘贴到一个新的功能文件中,并查看它是否可以自己运行:

* def response = 
"""
{
    "id": 0,
    "rc": "51",
    "product": {
        "code": "28",
        "label": "PLN",
        "type": "electricity",
        "ops": "PLN",
        "nominal": 50000
    },
    "cust_id": "01428800200",
    "order_id": "",
    "ref_no": "2033930693200733",
    "amount": 50000,
    "price": 50000,
    "created": -62135596800
}
"""
* def schema =
"""
{
  "id": "#number",
  "rc": "#string",
  "product": {
    "code": "#string",
    "label": "#string",
    "type": "#string",
    "ops": "#string",
    "nominal": "#number"
  },
  "cust_id": "#string",
  "order_id": "#string",
  "ref_no": "#string",
  "amount": "#number",
  "price": "#number",
  "created": "#number? _ < 0"
}
"""
* match response == schema