Skip to content

Commit 3aa9d07

Browse files
committed
Improve unevaluatedProperties prose
Signed-off-by: Juan Cruz Viotti <[email protected]>
1 parent 5ed0f5d commit 3aa9d07

File tree

1 file changed

+48
-12
lines changed

1 file changed

+48
-12
lines changed

content/2020-12/unevaluated/unevaluatedProperties.markdown

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,54 @@ related:
2727
keyword: unevaluatedItems
2828
---
2929

30-
Validation with `unevaluatedProperties` applies only to the child values of instance names that do not appear in the `properties`, `patternProperties`, `additionalProperties`, or `unevaluatedProperties` annotation results that apply to the instance location being validated. For all such properties, validation succeeds if the child instance validates against the `unevaluatedProperties` schema.
31-
32-
## Evaluation
33-
34-
It's crucial to understand what evaluation means in this context.
35-
36-
`unevaluatedProperties` considers annotations from `properties`, `patternProperties`, and `additionalProperties`, both as adjacent keywords and in subschemas of adjacent keywords. Additionally, it is also affected by other `unevaluatedProperties` in nested schemas (if present).
37-
38-
- The keywords `properties`, `patternProperties`, `additionalProperties`, and `unevaluatedProperties` produce annotations for the properties they successfully validate against.
39-
- If any of these keywords generate an annotation for a particular property at the same instance location (independently of the schema location), that property is considered as evaluated.
40-
- By definition, the `unevaluatedProperties` subschema is always applied after `properties`, `patternProperties`, and `additionalProperties` subschemas.
41-
- As its name implies, `unevaluatedProperties` applies to any object property that has not been previously evaluated.
30+
The [`unevaluatedProperties`]({{< ref
31+
"2020-12/unevaluated/unevaluatedproperties" >}}) keyword is a generalisation of
32+
the [`additionalProperties`]({{< ref "2020-12/applicator/additionalproperties"
33+
>}}) keyword that considers related keywords even when they are not direct
34+
siblings of this keyword. More specifically, this keyword is affected by
35+
occurences of [`properties`]({{< ref "2020-12/applicator/properties" >}}),
36+
[`patternProperties`]({{< ref "2020-12/applicator/patternproperties" >}}),
37+
[`additionalProperties`]({{< ref "2020-12/applicator/additionalproperties"
38+
>}}), and [`unevaluatedProperties`]({{< ref
39+
"2020-12/unevaluated/unevaluatedproperties" >}}) itself as long as the evaluate
40+
path that led to [`unevaluatedProperties`]({{< ref
41+
"2020-12/unevaluated/unevaluatedproperties" >}}) is a prefix of the evaluate
42+
path of the others.
43+
44+
{{<best-practice>}}
45+
46+
There are two common use cases for this keyword, both for reducing duplication:
47+
(1) Elegantly describing _additional_ object properties while declaring the
48+
[`properties`]({{< ref "2020-12/applicator/properties" >}}) or
49+
[`patternProperties`]({{< ref "2020-12/applicator/patternproperties" >}})
50+
keywords behind conditional logic without duplicating the
51+
[`additionalProperties`]({{< ref "2020-12/applicator/additionalproperties"
52+
>}}) keyword in every possible branch. (2) Re-using
53+
the [`properties`]({{< ref "2020-12/applicator/properties" >}}) and
54+
[`patternProperties`]({{< ref "2020-12/applicator/patternproperties" >}})
55+
keywords, or the [`additionalProperties`]({{< ref
56+
"2020-12/applicator/additionalproperties" >}}) keyword, as helpers while
57+
specialising the helpers with other related keywords as needed in specific
58+
locations without having to inline the entire helper.
59+
60+
{{</best-practice>}}
61+
62+
{{<learning-more>}}
63+
64+
The JSON Schema specification defines the relationship between this keyword and
65+
the ones that affect it in terms of annotations. However, in practice, most
66+
implementations avoid the use of annotations for performance reasons, as
67+
emitting annotations and checking the annotation values of other keywords often
68+
involves significant memory allocation and complex data structure traversals.
69+
70+
The paper [Elimination of annotation dependencies in validation for Modern JSON
71+
Schema](https://arxiv.org/abs/2503.11288) is a comprehensive mathematical study
72+
of how applicators can be automatically re-written to avoid annotation
73+
dependencies, leading to schemas that are simpler to evaluate.
74+
75+
{{</learning-more>}}
76+
77+
{{<constraint-warning `object`>}}
4278

4379
## Examples
4480

0 commit comments

Comments
 (0)