$recursiveAnchor : Boolean

$recursiveAnchor

Boolean

This keyword is used to dynamically identify a base URI at runtime by marking where such a calculation can start, and where it stops.

Value This keyword must be set to a boolean that determines whether the reference destination is must be determined by examining the dynamic scope or not Hint: Use the jsonschema metaschema and jsonschema lint commands to catch keywords set to invalid values
Kind Identifier
Applies To Any
Base Dialect 2019-09
Changed In None
Introduced In 2019-09
Vocabulary Core
Specification https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02#rfc.section.8.2.4.2.2
Metaschema https://json-schema.org/draft/2019-09/meta/core
Official Tests draft2019-09/recursiveRef.json
Default false
Annotation None
Affected By None
Affects
Also See

The $recursiveAnchor keyword is an extension of the $anchor keyword that, when set to true, associates a subschema with a special empty URI fragment identifier and records this association in the dynamic scope. When resolving this anchor using the $recursiveRef keyword, the base URI of the origin is not considered. Instead, evaluation jumps to the first encountered occurrence of the given recursive anchor in the stack of schema resources traversed so far.

To debug which recursive anchor the evaluation process is jumping to, try the jsonschema validate command with the --trace option. This option prints a trace of every step in the evaluation process alongside the corresponding keywords and their respective locations, letting you know which destination was preferred when encountering a recursive reference. For example:

$ jsonschema validate custom-metaschema.json schema.json --trace
...

-> (push) "/$ref/allOf/1/$ref/properties/additionalProperties/$recursiveRef" (ControlDynamicAnchorJump)
   at "/additionalProperties"
   at keyword location "https://json-schema.org/draft/2019-09/meta/applicator#/properties/additionalProperties/$recursiveRef"
   at vocabulary "https://json-schema.org/draft/2019-09/vocab/core"

-> (push) "/$ref/allOf/1/$ref/properties/additionalProperties/$recursiveRef/properties" (LogicalWhenType)
   at "/additionalProperties"
   at keyword location "https://example.com/custom-metaschema#/properties"
   at vocabulary "https://json-schema.org/draft/2019-09/vocab/applicator"
...

Examples

A custom meta-schema that extends the JSON Schema 2019-09 dialect with a custom keyword Schema
{
  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "$id": "https://example.com/custom-metaschema",
  "$recursiveAnchor": true,
  "$ref": "https://json-schema.org/draft/2019-09/schema",
  "properties": {
    "my-custom-keyword": { "type": "string" }
  }
}
Valid An object with a top-level occurrence of the custom keyword is valid Instance
{ "my-custom-keyword": "foo" }
Annotations
{ "keyword": "/properties", "instance": "", "value": [ "my-custom-keyword" ] }
Valid An object with a nested occurrence of the custom keyword is valid Instance
{ "additionalProperties": { "my-custom-keyword": "foo" } }
Annotations
{ "keyword": "/properties", "instance": "/additionalProperties", "value": [ "my-custom-keyword" ] }
Invalid An object with an incorrect nested occurrence of the custom keyword is invalid Instance
{ "additionalProperties": { "my-custom-keyword": 1 } }