3

考虑这个例子:

"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\"}}";

我错过了架构中的任何内容吗?谢谢

4

1 回答 1

4

您的架构可以这样扩展:

allof:它必须independently针对两种模式进行验证:

  • 第一个具有通过ref.
  • 第二个不允许任何属性"additionalProperties" : false,除了那些在空集中定义的属性"properties" : {}。换句话说,它不能有任何属性。

这个问题可能在标准草案 5 中得到解决。下面的 SO question对此有更多的了解。

于 2016-08-03T16:18:06.883 回答