邮递员阵列架构验证 [英] Postman array schema validation
本文介绍了邮递员阵列架构验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
邮递员中的数组json模式验证存在问题.
I have the problem with array json schema validation in postman.
var schema = {
"type": "array",
"items": [{
"id": {
"type":"long"
},
"name": {
"type":"string"
},
"email": {
"type":"string"
}
}]
};
pm.test('Response schema type nodes verification', function() {
pm.expect(tv4.validate(pm.response.json(), schema)).to.be.true;
});
响应主体为:
[
{
"id": 1,
"name": "test1",
"email": "a@a.com"
},
{
"id": 2,
"name": "test2",
"email": "a@a.com"
},
.
.
.
]
我总是通过结果.我也尝试了删除[]
.
I have always passed result. Also I tried with removed []
.
问题出在哪里?
推荐答案
所使用的架构不正确,您需要将数组中的项目类型定义为object
.正确的JSON模式如下所示:
The schema used in question is incorrect, you need to define the type of item in array as object
. The correct JSON schema would look like:
var schema = {
"type": "array",
"items": [{
type: "object",
properties:{
"id": {
"type":"integer"
},
"name": {
"type":"string"
},
"email": {
"type":"string"
}
}
}]
};
pm.test('Response schema type nodes verification', function() {
pm.expect(tv4.validate(pm.response.json(), schema)).to.be.true;
});
请注意,JSON模式中只有2个数字类型:integer
和number
.没有任何类型为long
.
Please note there are only 2 numeric types in JSON Schema: integer
and number
. There is no type as long
.
这篇关于邮递员阵列架构验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文