我有一个以格式返回响应的 API
[
{"id": 12345,
"value": "some_string",
"practice_id": "12344"},
{"id": 12346,
"value": "some_other_string",
"practice_id": "12345"},
]
我正在测试响应是否验证特定的 JSON 模式,我的模式测试是
response.body.should.have.schema({
type: 'array',
required: ['id', 'value', 'practice_id'],
properties: {
id: {
type: 'number',
},
value: {
type: 'string',
},
practice_id: {
type: 'string',
minLength: 5,
}
}
});
问题是,即使我将 id 的类型更改为 string
或将 practice_id 的值更改为 number
,测试仍然通过,这是不正确的。
我在这里做错了什么?我正在使用 Postman-BDD验证响应。
最佳答案
我猜你的模式应该更像这样:
{
"type": "array",
"items":
{
"required":
[
"id",
"value",
"practice_id"
],
"properties":
{
"id":
{
"type": "number"
},
"value":
{
"type": "string"
},
"practice_id":
{
"type": "string",
"minLength": 5
}
}
}
}
关于javascript - 针对 JSON 模式验证 JS 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47750305/