@@ -450,42 +450,54 @@ further change the assertion result.
450
450
451
451
While most JSON Schema keywords can be evaluated on their own, or at most need
452
452
to take into account the values or results of adjacent keywords in the same
453
- schema object, a few have more complex behavior.
453
+ schema object, a few have more complex behavior. This behavior is generally
454
+ governed by the scope of the keyword.
454
455
455
- The lexical scope of a keyword is determined by the nested JSON data structure
456
- of objects and arrays. The largest such scope is an entire schema document. The
457
- smallest scope is a single schema object with no subschemas.
456
+ This specification defines two such scopes: lexical and dynamic.
457
+
458
+ #### Lexical Scope
458
459
459
- Keywords MAY be defined with a partial value, such as a IRI reference, which
460
- must be resolved against another value, such as another IRI reference or a full
461
- IRI, which is found through the lexical structure of the JSON document. The
462
- ` $id ` , ` $ref ` , and ` $dynamicRef ` core keywords, and the "base" JSON Hyper-Schema
463
- keyword, are examples of this sort of behavior.
460
+ The lexical scope of a keyword is determined by the nested JSON data structure
461
+ of objects and arrays. The smallest such scope is a single schema object with no
462
+ subschemas. The largest scope is an entire schema document, recursively
463
+ including all of its subschemas.
464
+
465
+ Keywords MAY be defined with a partial value which must be resolved against
466
+ another value found within the lexical structure of the JSON document. The
467
+ ` $id ` , ` $schema ` , and ` $ref ` core keywords, and the ` base ` JSON Hyper-Schema
468
+ keyword, are some such keywords. For example, an ` $id ` keyword found in an
469
+ embedded schema resource may have a value that is a relative IRI. This value
470
+ must be resolved against another ` $id ` keyword found in an ancestor subschema,
471
+ or the root schema, to produce an absolute IRI which fully identifies that
472
+ embedded schema resource.
464
473
465
474
Note that some keywords, such as ` $schema ` , apply to the lexical scope of the
466
475
entire schema resource, and therefore MUST only appear in a schema resource's
467
- root schema.
476
+ root object.
477
+
478
+ #### Dynamic Scope
468
479
469
- Other keywords may take into account the dynamic scope that exists during the
470
- evaluation of a schema, typically together with an instance document. The
471
- outermost dynamic scope is the schema object at which processing begins, even if
472
- it is not a schema resource root. The path from this root schema to any
473
- particular keyword (that includes any ` $ref ` and ` $dynamicRef ` keywords that may
474
- have been resolved) is considered the keyword's "evaluation path."
480
+ The dynamic scope is the ordered collection of schema resources navigated during
481
+ evaluation, starting at the root and ending at the schema resource which
482
+ contains the subschema under evaluation. The outermost dynamic scope is the
483
+ schema resource at which processing begins. The path that evaluation takes,
484
+ starting from the subschema to any particular subschema (including any ` $ref `
485
+ and ` $dynamicRef ` keywords that may have been resolved), is considered the
486
+ "evaluation path".
475
487
476
488
Lexical and dynamic scopes align until a reference keyword is encountered. While
477
- following the reference keyword moves processing from one lexical scope into a
478
- different one, from the perspective of dynamic scope, following a reference is
479
- no different from descending into a subschema present as a value . A keyword on
480
- the far side of that reference that resolves information through the dynamic
481
- scope will consider the originating side of the reference to be their dynamic
482
- parent, rather than examining the local lexically enclosing parent.
489
+ following the reference moves processing from one lexical scope into a different
490
+ one, from the perspective of dynamic scope, following a reference is no
491
+ different from descending into a subschema. A keyword on the far side of the
492
+ reference that resolves information through the dynamic scope will consider the
493
+ originating side of the reference to be its dynamic parent rather than examining
494
+ the local lexically enclosing parent.
483
495
484
496
The concept of dynamic scope is primarily used with ` $dynamicRef ` and
485
497
` $dynamicAnchor ` , and should be considered an advanced feature and used with
486
498
caution when defining additional keywords. It also appears when reporting errors
487
499
and collected annotations, as it may be possible to revisit the same lexical
488
- scope repeatedly with different dynamic scopes. In such cases , it is important
500
+ scope repeatedly with different dynamic scopes. For this reason , it is important
489
501
to inform the user of the evaluation path that produced the error or annotation.
490
502
491
503
### Keyword Interactions
@@ -894,8 +906,10 @@ If this IRI identifies a retrievable resource, that resource SHOULD be of media
894
906
type ` application/schema+json ` .
895
907
896
908
The ` $schema ` keyword SHOULD be used in the document root schema object, and MAY
897
- be used in the root schema objects of embedded schema resources. When the
898
- keyword appears in a non-resource root schema object, the behavior is undefined.
909
+ be used in the root schema objects of embedded schema resources. This keyword
910
+ MUST NOT appear in a subschema that is not also the root object of a schema
911
+ resource (see {{id-keyword}} for more information regarding defining embedded
912
+ schema resources.)
899
913
900
914
Values for this property are defined elsewhere in this and other documents, and
901
915
by other parties.
@@ -917,8 +931,9 @@ to establish a base IRI in order to resolve the reference.
917
931
#### The ` $id ` Keyword {#id-keyword}
918
932
919
933
An ` $id ` keyword in a schema or subschema identifies that schema or subschema as
920
- a distinct schema resource. The value for this keyword MUST be a string, and
921
- MUST represent a valid IRI reference without a fragment.
934
+ a distinct schema resource and applies to the entire lexical scope of that
935
+ schema resource. The value for this keyword MUST be a string, and MUST represent
936
+ a valid IRI reference without a fragment.
922
937
923
938
When the value of this keyword is resolved against the current base IRI, the
924
939
resulting absolute IRI then serves as the identifier for the schema resource and
0 commit comments