[英]json-schema passes validation if an array is passed instead of an object
这是我在我们的应用程序中管理配置文件的模式:
var ProfileJsonSchema = {
properties: {
Profiles: {
optional: false,
items: {
optional: false,
properties: {
Email: {type: String},
FirstName: {type: String},
Zip: {type: String},
City: {type: String}
}}}};
和我的数据
[{}]
和要测试的代码
validation = Validate([{}], ProfileJsonSchema);
if (!validation.valid) {
return;
}
// do something...
嗯,验证没问题。 为什么 ? 有没有办法处理这种类型的错误?
为了回答这个晚了十年,缺少 json 模式type
断言。 如果没有这个,任何类型都是有效的。 properties
断言可能看起来只允许对象,但实际上,它只断言if a property Profiles exists then it must satisfy the declared subschema
。 由于Profiles
甚至不是必需的属性,因此任何没有Profiles
属性的对象也是有效的。
这里可能有一个错字:
validation = Validate([{}], , ProfileJsonSchema);
3 个参数而不是 2 个?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.