如何在 JSON 架构中将 additionalProperties 与 allOf 一起使用?
How to use additionalProperties with allOf in JSON schema?
考虑这个例子:
"allOf": [
{"$ref": "test-address-prefix-types-base.json#"},
{
"properties": {}, "additionalProperties" : false
}
]}
当我使用 Java 模式验证器验证它时,我收到错误消息:
"keyword":"additionalProperties","message":"object instance has properties which are not allowed by the schema: [\"attributes\",\"type\"]"}]
但是针对基本架构 (test-address-prefix-types-base) 验证的同一 JSON 对象没有错误地通过。
引用的架构(基础架构)没有设置附加属性。
这是我正在使用的 json 消息:
String message = "{\"data\":{\"attributes\":{" +
"\"notation\": \"A\"," +
"\"prefixType\": \"A\"}" +
",\"type\":\"test-address-prefix-types\"}}";
我是否遗漏了架构中的任何内容?
谢谢
您的架构可以这样扩展:
allof
:它必须针对两个模式验证 independently
:
- 第一个具有通过
ref
链接的任意属性。
- 第二个不允许任何 属性
"additionalProperties" : false
除了在空集 "properties" : {}
中定义的那些。也就是说,它不能有任何属性。
这个问题可能会在标准的 draft-5 中得到解决。 the following SO question.
中有更多相关信息
考虑这个例子:
"allOf": [
{"$ref": "test-address-prefix-types-base.json#"},
{
"properties": {}, "additionalProperties" : false
}
]}
当我使用 Java 模式验证器验证它时,我收到错误消息:
"keyword":"additionalProperties","message":"object instance has properties which are not allowed by the schema: [\"attributes\",\"type\"]"}]
但是针对基本架构 (test-address-prefix-types-base) 验证的同一 JSON 对象没有错误地通过。
引用的架构(基础架构)没有设置附加属性。
这是我正在使用的 json 消息:
String message = "{\"data\":{\"attributes\":{" +
"\"notation\": \"A\"," +
"\"prefixType\": \"A\"}" +
",\"type\":\"test-address-prefix-types\"}}";
我是否遗漏了架构中的任何内容? 谢谢
您的架构可以这样扩展:
allof
:它必须针对两个模式验证 independently
:
- 第一个具有通过
ref
链接的任意属性。 - 第二个不允许任何 属性
"additionalProperties" : false
除了在空集"properties" : {}
中定义的那些。也就是说,它不能有任何属性。
这个问题可能会在标准的 draft-5 中得到解决。 the following SO question.
中有更多相关信息