我已经根据响应编写了一个架构,但是没有定义属性类型?

时间:2019-12-02 01:05:20

标签: json api schema postman

我写了一个架构来测试Postman中的API。根据响应,未定义任何属性,但是通过调查API,我假定该属性为Image,因此已包含该属性。运行测试架构时,我收到以下消息:AssertionError:无效的类型:字符串(预期的对象):预期的false等于true。有人可以给我他们的专业知识,因为这是我第一次使用Postman并编写模式,该怎么办?我的想法是,因为没有定义属性,所以我必须以某种方式在架构中添加一些语法,如果是这种情况,您能告诉我我缺少什么吗?

架构如下:

tests["Status code is 200"] = pm.response.to.have.status(200);
var schema = {
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "Images": {
           "type": "string",
           "pattern": "^(.*)$"
         }
        }
    }
};
pm.test('Schema is valid', function () {
    var response = pm.response.json();
    var result = tv4.validateResult(response, schema, false, true);
    pm.expect(result.valid).to.equal(true, result.valid ? null : result.error.message);
});  

响应为:

[
    "https://vtappdataqa.blob.core.windows.net/event/V2MA61600457_2018-08-22T08.15.54-1.jpg?sv=2018-03-28&sr=b&sig=nPCIn4HJ7KlCkrBT52ylP%2Fl8%2FSuLDoJc046bE17DBDk%3D&st=2019-12-02T00%3A44%3A52Z&se=2019-12-02T01%3A44%3A52Z&sp=r",
    "https://vtappdataqa.blob.core.windows.net/event/V2MA61600457_2018-08-22T08.15.54-2.jpg?sv=2018-03-28&sr=b&sig=6jj2MAv9b3FjacMKBegdOCg82hpE12%2Bq4AMKLsTOwg8%3D&st=2019-12-02T00%3A44%3A52Z&se=2019-12-02T01%3A44%3A52Z&sp=r",
    "https://vtappdataqa.blob.core.windows.net/event/V2MA61600457_2018-08-22T08.15.54-3.jpg?sv=2018-03-28&sr=b&sig=VIgEMXJUI2dFhEVB02igCBk0isyVHEBEGYs4wWNUkr0%3D&st=2019-12-02T00%3A44%3A52Z&se=2019-12-02T01%3A44%3A52Z&sp=r",
    "https://vtappdataqa.blob.core.windows.net/event/V2MA61600457_2018-08-22T08.15.54-4.jpg?sv=2018-03-28&sr=b&sig=Wp%2BDtcxsuJwDVDMr8n6X0PCPWkpfEVy7qCwrhItDAoA%3D&st=2019-12-02T00%3A44%3A52Z&se=2019-12-02T01%3A44%3A52Z&sp=r",
    "https://vtappdataqa.blob.core.windows.net/event/V2MA61600457_2018-08-22T08.15.54-5.jpg?sv=2018-03-28&sr=b&sig=Smde5J%2FNv68foKtbwxtmSL087Xbrq7Fl394ORUIFWI8%3D&st=2019-12-02T00%3A44%3A52Z&se=2019-12-02T01%3A44%3A52Z&sp=r",
    "https://vtappdataqa.blob.core.windows.net/event/V2MA61600457_2018-08-22T08.15.54-6.jpg?sv=2018-03-28&sr=b&sig=FGeEkwm9Z3Enm%2BmNsZa4Whlm5uxCtEUGyNGDQEO%2Bdqc%3D&st=2019-12-02T00%3A44%3A52Z&se=2019-12-02T01%3A44%3A52Z&sp=r",
    "https://vtappdataqa.blob.core.windows.net/event/V2MA61600457_2018-08-22T08.15.54-7.jpg?sv=2018-03-28&sr=b&sig=x97S1NFmgpJV0e%2B36eH0NdALxk85bDywhzDwQ%2FSQZB8%3D&st=2019-12-02T00%3A44%3A52Z&se=2019-12-02T01%3A44%3A52Z&sp=r",
    "https://vtappdataqa.blob.core.windows.net/event/V2MA61600457_2018-08-22T08.15.54-8.jpg?sv=2018-03-28&sr=b&sig=BmEkIXcU3jSfiFj5llRoAfxqlVMms%2FGiSREVNZVs6DI%3D&st=2019-12-02T00%3A44%3A52Z&se=2019-12-02T01%3A44%3A52Z&sp=r",
    "https://vtappdataqa.blob.core.windows.net/event/V2MA61600457_2018-08-22T08.15.54-9.jpg?sv=2018-03-28&sr=b&sig=xLd12jSTxqSPOyAvj6UaI1cGbpo1ny4I4VJCcaCLaLs%3D&st=2019-12-02T00%3A44%3A52Z&se=2019-12-02T01%3A44%3A52Z&sp=r",
    "https://vtappdataqa.blob.core.windows.net/event/V2MA61600457_2018-08-22T08.15.54-10.jpg?sv=2018-03-28&sr=b&sig=gc2n5odUZ0wNga08kr9XymLLqMLStBjlhpRlhRVElNI%3D&st=2019-12-02T00%3A44%3A52Z&se=2019-12-02T01%3A44%3A52Z&sp=r"
]

0 个答案:

没有答案