POSTMAN - 即使对于不正确的测试数据,也会传递模式验证

时间:2017-11-06 10:15:06

标签: json schema postman

测试["验证模式"] = tv4.validate(testdata,schema)即使"代码"和"状态"缺少测试数据。如何确保响应和测试数据模式都与JSON模式匹配。

  var testdata={
"csosProfileDataList": [
{
  "profileName": "cameron test",
  "deaRegisteredName": "COLISEUM SAME DAY SURG CTR#712",
  "deaLicenseNo": "BP6117004",
},
{
  "profileName": "Vaseem!@#$%%",
  "code": 69022,
  "deaRegisteredName": "COLISEUM SAME DAY SURG CTR#712",
  "deaLicenseNo": "BP6117004",
  "status": "COMPLETE"
}
]
};

 var schema={
"type":"object",
"properties":{
"csosProfileData":{
    "type":"array",
    "items":{
        "type":"object", 
    "properties":{
    "profileName":{"type":"string"},
    "code":{"type":"string"},
    "deaRegistrationName":{"type":"string"},
    "deaLicenseNo":{"type":"string"},
    "status":{"type":"string"}
},
 "required":["profileName", "code", "deaRegistrationName", "deaLicenseNo", "status"]
    }

}
}

};
tests["validating schema "] = tv4.validate(testdata, schema);

1 个答案:

答案 0 :(得分:0)

您的架构中存在一些拼写错误,这就是它无法正确验证的原因。由于拼写错误,验证器未使用项目信息进行验证,并且仅验证根是对象。我已经包含了更新的架构。

let schema = {
"type":"object",
"required" : ["csosProfileDataList"],
"properties":{
    "csosProfileDataList":{
        "type":"array", 
        "items" : [{
            "type":"object",
            "required":["profileName", "code", "deaRegisteredName", "deaLicenseNo", "status"],
            "properties":{
                "profileName":{"type":"string"},
                "code":{"type":"string"},
                "deaRegisteredName":{"type":"string"},
                "deaLicenseNo":{"type":"string"},
                "status":{"type":"string"}
            }
        }]
    }
}};

测试时,我通常会在测试后添加一些日志记录,以便我可以看到它可能失败的地方

console.log(JSON.stringify(tv4));