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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

So the question is, this "merge" is only a proposal and not released yet, right? I've checked the json schema spec in json-schema.org and there is no mention of it. We are using AJV to validate and that's not supporting the merge yet.
Yes, you can not apply it safely yet. If possible, you may add "additionalProperties" : false to the referenced schema.
Do you know if Json Schema Validator (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 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.