Skip to content

schema.json mandates infinite recursion via $ref #263

Closed
@erayd

Description

@erayd

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:

  1. Validating some object against the root schema
  2. items is not set
  3. Set items to an empty object
  4. 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions