1
votes

The topic sounds quite a bit confusing, doesn't it?

As far as I understand "JsonSchema-Validation" there is a standard JsonSchema under "json-schema.org/schema#" that should define the allowed structure for other JsonSchemas. This standard JsonSchema at "json-schema.org/schema#" is a JsonFile itself (as any other JsonSchema would be) and is also a JsonSchema.

Now to the point of my own confusion: When I validate this specific standard JsonSchema against itself, I get errors around the JsonNodes/JsonObject-PropertyKeys "additionalProperties".

As described at "json-schema.org/example2.html" the PropertyKeys "additionalProperties" should be at the same level as the PropertyKeys "properties". But in the standard JsonSchema they are not. They are inside the JsonObject contained in Propertykey "properties".

What do I get wrong?

Second issue: What does the reference entry "$ref": "#" mean? What definition entry does it refer to? The normal reference entry should look more like: "$ref": "#/definitions/positiveInteger"

Any help is appreciated.

with kind regards HuDeanY

1

1 Answers

3
votes

Let's break the schema down a bit to make things a little more clear. If I understand you correctly, this is the part that is tripping you up.

{
  ...
  "properties": {
    ...
    "properties": {
      "type": "object",
      "additionalProperties": { "$ref": "#" },
      "default": {}
    },
    ...
  },
}

The tricky part is that you have to realize that the second "properties" is not a keyword, it's a property name. This is the meta-schema defining the properties keyword. So, this is not a case of nesting the additionalProperties keyword inside the properties keyword as it might seem at first glance.


The "#" refers to the root of the document. So, { "$ref": "#" } is a recursive reference. In other words, "#" is the refers to the whole meta-schema. The schema segment above defines the properties keyword as an object who's values are schemas.


Finally, I can assure you that any properly functioning validator will successfully validate any valid schema (including the meta-schema itself) against the meta-schema. If it doesn't, it is a bug in the validator and should be reported to maintainer of the validation library you are using.