如何在JSON模式中将additionalProperties与allOf一起使用?
考虑这个例子:如何在JSON模式中将additionalProperties与allOf一起使用?,json,jsonschema,json-schema-validator,Json,Jsonschema,Json Schema Validator,考虑这个例子: "allOf": [ {"$ref": "test-address-prefix-types-base.json#"}, { "properties": {}, "additionalProperties" : false } ]} 当我用Java schema validator验证时,我得到的错误是: "keyword":"additionalProperties","message":"object instance has pro
"allOf": [
{"$ref": "test-address-prefix-types-base.json#"},
{
"properties": {}, "additionalProperties" : false
}
]}
当我用Java schema validator验证时,我得到的错误是:
"keyword":"additionalProperties","message":"object instance has properties which are not allowed by the schema: [\"attributes\",\"type\"]"}]
但是,根据基本模式(测试地址前缀类型base)验证的同一个JSON对象没有错误地通过
引用的架构(基本架构)未设置additionalProperties
这是我正在使用的json消息:
String message = "{\"data\":{\"attributes\":{" +
"\"notation\": \"A\"," +
"\"prefixType\": \"A\"}" +
",\"type\":\"test-address-prefix-types\"}}";
我在模式中遗漏了什么吗?
谢谢您的模式可以通过以下方式扩展:
allof
:它必须根据两个模式独立地验证:
- 第一个具有通过
ref
链接的任意属性
- 第二个不允许任何属性
“additionalProperties”:false
,除了在空集“properties”:{}
中定义的属性之外。换句话说,它不能有任何属性李>
该问题可在本标准草案5中解决。关于这方面的更多信息,请参见。问题是,这项“合并”只是一项提案,尚未发布,对吗?我已经检查了json模式规范,但没有提到它。我们正在使用AJV进行验证,但还不支持合并。是的,您还不能安全地应用它。如果可能,您可以向引用的模式添加“additionalProperties”:false。您知道Json模式验证器()是否支持$merge吗?我刚刚意识到AJV添加了对$merge的支持,但我们使用的是Json模式验证器,它是针对Java的,从这里我可以看到它支持$merge,但我就是不能让它工作?它返回错误,因为无法识别$merge