Postman Schema验证JSON数组

时间:2018-04-30 16:20:42

标签: postman json-schema-validator

我的测试数据:

 {
     "staffId": 1691580015,
     "staffName": "Test Staff",
     "staffEmail": "teststaff@perpule.com",
     "isAdmin": null,
     "isSuperAdmin": null,
     "shopDetails": [
         {
             "shopId": 5004,
             "shopName": "Spar E2E",
             "shopAddress": "Nagpur",
             "shopLocality": "Nagpur",
             "shopCity": "Nagpur",
             "shopState": "Maharashtra",
             "stateCode": "KT"
             }]

     }

我的测试用例代码:

var schema = {  
   //"required":["shopDetails"],
   "type":"object",
   "properties":{  
      "shopDetails":{  
         "type":"array",
         "items":[  
            {  
               "type":"object",
               "properties":{  
                  "shopId":{  
                     "type":"integer"
                  },
                  "shopName":{  
                     "type":"string"
                  },
                  "shopAddress":{  
                     "type":"string"
                  }
               }
            }
         ]
      }
   }
}  


//console.log(JSON.stringify(tv4));
pm.test('Schema is valid', function() {
  pm.expect(tv4.validate(jsonData, schema)).to.be.true;
});

问题是每次失败,如何解决请帮忙?

0 个答案:

没有答案