首页 > 解决方案 > all key-values did not match for jsonschema

问题描述

I have jsonschema like this below :

{
    "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
}

and this is my schema validation

{
  "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"
}

but I get message reason: all key-values did not match , but I think that my schema is correct, so does anyone can help me with this ??

标签: karate

解决方案


这对我有用,你的脚本中一定有一些错误。将以下内容粘贴到一个新的功能文件中,看看它是否适合您自己:

* 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

推荐阅读