简体   繁体   中英

How to use additionalProperties with allOf in JSON schema?

Consider this example:

"allOf": [
    {"$ref": "test-address-prefix-types-base.json#"},
    {
        "properties": {}, "additionalProperties" : false
    }
]}

When I validate this with Java schema validator, I get error saying:

"keyword":"additionalProperties","message":"object instance has properties which are not allowed by the schema: [\"attributes\",\"type\"]"}]

but the same JSON object validated against the base schema (test-address-prefix-types-base) passes without error.

The referenced schema (base one) doesn't have additionalProperties set.

This is the json message I am using:

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

Have I missed anything in schema? Thanks

Your schema could be expanded this way:

allof : It must validate independently against two schemas:

  • First one with arbitrary properties linked through ref .
  • The second one which does not allow any property "additionalProperties" : false except those defined in the empty set "properties" : {} . In other words, it can not have any property.

This problem may be solved in draft-5 of the standard. More on this in the following SO question .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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