Skip to content

Commit e90e1ec

Browse files
committed
Improve descriptions for unevaluatedItems
Signed-off-by: Juan Cruz Viotti <[email protected]>
1 parent cf92b5d commit e90e1ec

File tree

1 file changed

+46
-12
lines changed

1 file changed

+46
-12
lines changed

content/2020-12/unevaluated/unevaluatedItems.markdown

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,52 @@ related:
2727
keyword: unevaluatedProperties
2828
---
2929

30-
If no relevant annotations are present, the `unevaluatedItems` subschema must be applied to all locations in the array. If a boolean true value is present from any of the relevant annotations, `unevaluatedItems` is ignored. Otherwise, the subschema must be applied to any index greater than the largest annotation value for `prefixItems`, which does not appear in any annotation value for `contains`.
31-
32-
## Evaluation
33-
34-
It's crucial to understand what evaluation means in this context.
35-
36-
`unevaluatedItems` considers annotations from `prefixItems`, `items`, and `contains`, both as adjacent keywords and in subschemas of adjacent keywords. Additionally, it is also affected by other `unevaluatedItems` in nested schemas (if present).
37-
38-
- The keywords `prefixItems`, `items`, `contains` and `unevaluatedItems` produce annotations for the indexes they successfully validate against.
39-
- If any of these keywords generate an annotation for a particular index, that index is considered as evaluated.
40-
- By definition, the `unevaluatedItems` subschema is always applied after `prefixItems`, `items`, and `contains` subschemas.
41-
- As its name implies, `unevaluatedItems` applies to any array index that has not been previously evaluated.
30+
The [`unevaluatedItems`]({{< ref "2020-12/unevaluated/unevaluateditems" >}})
31+
keyword is a generalisation of the [`items`]({{< ref "2020-12/applicator/items"
32+
>}}) keyword that considers related keywords even when they are not direct
33+
siblings of this keyword. More specifically, this keyword is affected by
34+
occurences of [`prefixItems`]({{< ref "2020-12/applicator/prefixitems" >}}),
35+
[`items`]({{< ref "2020-12/applicator/items" >}}), and [`unevaluatedItems`]({{<
36+
ref "2020-12/unevaluated/unevaluateditems"
37+
>}}) itself, as long as the evaluate path that led to
38+
[`unevaluatedItems`]({{< ref "2020-12/unevaluated/unevaluateditems"
39+
>}}) is a _prefix_ of the evaluate path of the others.
40+
41+
Given its evaluation-dependent nature, this keyword is evaluated after every
42+
other keyword from every other vocabulary.
43+
44+
{{<best-practice>}}
45+
46+
There are two common use cases for this keyword, both for reducing duplication:
47+
(1) Elegantly describing additional array items while declaring the
48+
[`prefixItems`]({{< ref "2020-12/applicator/prefixitems" >}}) keyword behind
49+
conditional logic without duplicating the [`items`]({{< ref
50+
"2020-12/applicator/items"
51+
>}}) keyword in every possible branch. (2) Re-using
52+
helpers that consist of the [`prefixItems`]({{< ref
53+
"2020-12/applicator/prefixitems" >}}) or [`items`]({{< ref
54+
"2020-12/applicator/items" >}}) keywords, while specialising the helpers as
55+
needed in specific locations without having to inline the entire contents of
56+
the helper.
57+
58+
{{</best-practice>}}
59+
60+
{{<learning-more>}}
61+
62+
The JSON Schema specification defines the relationship between this keyword and
63+
the ones that affect it in terms of annotations. However, in practice, most
64+
implementations avoid the use of annotations for performance reasons, as
65+
emitting annotations and checking the annotation values of other keywords often
66+
involves significant memory allocation and complex data structure traversals.
67+
68+
The paper [Elimination of annotation dependencies in validation for Modern JSON
69+
Schema](https://arxiv.org/abs/2503.11288) is a comprehensive mathematical study
70+
of how applicators can be automatically re-written to avoid annotation
71+
dependencies, leading to schemas that are simpler to evaluate.
72+
73+
{{</learning-more>}}
74+
75+
{{<constraint-warning `array`>}}
4276

4377
## Examples
4478

0 commit comments

Comments
 (0)