Description
If the following three points are all true:
items
is not set; and- Setting default values during validation is enabled; and
- Validating default values is enabled;
Then the result is infinite recursion:
- Validating some object against the root schema
items
is not set- Set
items
to an empty object - Validate the new empty object against the root schema (i.e. goto (1))
schema.json excerpt:
"items": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/schemaArray" }
],
"default": {}
},
The official spec document here says:
7. Schema references with $ref
A schema MUST NOT be run into an infinite loop against a schema. For example, if two schemas "#alice" and "#bob" both have an "allOf" property that refers to the other, a naive validator might get stuck in an infinite recursive loop trying to validate the instance. Schemas SHOULD NOT make use of infinite recursive nesting like this, the behavior is undefined.
The validation document here says:
6.2. "default"
There are no restrictions placed on the value of this keyword.This keyword can be used to supply a default JSON value associated with a particular schema. It is RECOMMENDED that a default value be valid against the associated schema.
This keyword MAY be used in root schemas, and in any subschemas.
My understanding from reading the above is that if default
is used in accordance with the spec, and validated as recommended, then schema.json
violates the no-infinite-recursion-via-$ref rule.
I am currently trying to resolve this issue in a validator library (see here) - have I badly misunderstood things here, and / or is there a recommended way of dealing with the situation?