我正在尝试验证我的 JSON 模式并使用 additionalProperties: false 来确认没有其他属性。我的 responseBody 如下所示:
[
{
"id": 1234567890987654,
"email": "eemail@domain.com",
"civility": 0,
"firstname": "john",
"lastname": "do",
"function": null,
"phone": null,
"cellphone": null,
"role": 1,
"passwordws": "jdnfjnshn55fff5g8"
},
{
...}
]
在邮递员测试中,我添加了这个
var schema = {
"type": "array",
"properties": {
"id": {"type":"number"},
"email": {"type":"string"},
"civility": {"type":"number"},
"firstname": {"type":"string"},
"lastname": {"type":"string"},
"function": {"type":"string"},
"cellphone": {"type":"string"},
"role": {"type":"number"},
"passwordws": {"type":"string"},
},
"additionalProperties": false,
"required": ["id", "email", "civility", "role", "passwordws"]
};
var data = JSON.parse(responseBody);
var result = tv4.validateResult(data, schema);
tests["Valid schema"] = result.valid;
测试应该返回失败,因为我从架构中删除了“电话”属性,但测试仍然运行有效......我试图将架构更改为 {type:array, properties: {type: object, properties {list of properties}additionalProperties : false}} 但测试仍然返回 PASS 而不是 FAIL ......知道吗?