繁体   English   中英

如何在JSON模式中将allProf与additionalProperties一起使用?

[英]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\"]"}]

但是针对基本模式验证的相同JSON对象(test-address-prefix-types-base)没有错误地传递。

引用的模式(基础模式)没有设置additionalProperties。

这是我正在使用的json消息:

        String message = "{\"data\":{\"attributes\":{" +
            "\"notation\": \"A\"," +
            "\"prefixType\": \"A\"}" +
            ",\"type\":\"test-address-prefix-types\"}}";

我在架构中错过了什么吗? 谢谢

您的架构可以通过以下方式扩展:

allof :它必须针对两个模式independently验证:

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

这个问题可以在标准草案5中解决。 以下SO问题更多相关内容

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM