3

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

xbmono
  • 2,084
  • 2
  • 30
  • 50

1 Answers1

4

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.

Community
  • 1
  • 1
jruizaranguren
  • 12,679
  • 7
  • 55
  • 73
  • So the question is, this "merge" is only a proposal and not released yet, right? I've checked the json schema spec in http://json-schema.org/ and there is no mention of it. We are using AJV to validate and that's not supporting the merge yet. – xbmono Aug 04 '16 at 03:53
  • 1
    Yes, you can not apply it safely yet. If possible, you may add "additionalProperties" : false to the referenced schema. – jruizaranguren Aug 04 '16 at 07:26
  • Do you know if Json Schema Validator (https://github.com/daveclayton/json-schema-validator) supports $merge? I just realized that AJV added the support of $merge but we are using Json schema validator which is for Java and from what I can see here https://github.com/daveclayton/json-schema-validator/wiki/v5:-merge it supports $merge but I just can't get it working? It returns errors as $merge is not recognized – xbmono Aug 19 '16 at 06:24