Skip to content

Commit 2c17ae0

Browse files
committed
Default behaviors; annotation-dependent results
Describe how default behaviors work in more detail, covering all three major keyword categories. Allow keywords to depend on the presence or absence of adjacent keywords (this is already true with "additionalItems" and "items'). Allow keywords to depend on the annotation results of subschemas and adjacent keywords. This is the fundamental mechanism behind the forthcoming "unevaluatedProperties" and "unevaluatedItems" keywords. The behavior of "additionalProperties" and "additionalItems" can be described with this mechanism (along with the presence or absence mechanism) as well, which will serve as a proof of concept of the approach in a subsequent commit.
1 parent e80b135 commit 2c17ae0

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

jsonschema-core.xml

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@
126126
<section title="Keyword Behaviors">
127127
<t>
128128
JSON Schema keywords fall into several general behavior categories.
129-
Assertions validate that an instance satisfies constraints. Annotations
130-
attach information that applications may use in any way they see fit.
129+
Assertions validate that an instance satisfies constraints, producing
130+
a boolean result. Annotations attach information that applications
131+
may use in any way they see fit.
131132
Applicators apply subschemas to parts of the instance and combine
132133
their results.
133134
</t>
@@ -145,6 +146,38 @@
145146
subschemas have been evaluated, although in some circumstance evaluation
146147
may be short-circuited due to assertion results.
147148
</t>
149+
<t>
150+
Keyword behavior MAY be defined in terms of the annotation results
151+
of <xref target="root">subschemas</xref> and/or adjacent keywords.
152+
Such keywords MUST NOT result in a circular dependency.
153+
Keywords MAY modify their behavior based on the presence or absence
154+
of another keyword in the same
155+
<xref target="schema-document">schema object</xref>.
156+
</t>
157+
<t>
158+
A missing keyword MUST NOT produce a false assertion result, MUST
159+
NOT produce annotation results, and MUST NOT cause any other schema
160+
to be evaluated as part of its own behavioral definition.
161+
However, given that missing keywords do not contribute annotations,
162+
the lack of annotation results may indirectly change the behavior
163+
of other keywords.
164+
</t>
165+
<t>
166+
In some cases, the missing keyword assertion behavior of a keyword is
167+
identical to that produced by a certain value, and keyword definitions
168+
SHOULD note such values where known. However, even if the value which
169+
produces the default behavior would produce annotation results if
170+
present, the default behavior still MUST NOT result in annotations.
171+
</t>
172+
<t>
173+
Because annotation collection can add significant cost in terms of both
174+
computation and memory, implementations MAY opt out of this feature.
175+
Keywords known to an implementation to have assertion or applicator behavior
176+
that depend on annotation results MUST then be treated as errors, unless
177+
an alternate implementation producing the same behavior is available.
178+
Keywords of this sort SHOULD describe reasonable alternate approaches
179+
when appropriate.
180+
</t>
148181
<t>
149182
Extension keywords SHOULD stay within these categories, keeping in mind
150183
that annotations in particular are extremely flexible. Complex behavior
@@ -190,9 +223,7 @@
190223
</t>
191224
<t>
192225
An instance can only fail an assertion that is present in the schema.
193-
In some cases, this no-op behavior is identical to a keyword that exists with
194-
certain values, and keyword definitions SHOULD note such values where known.
195-
These default behaviors MUST NOT result in assertion failures.
226+
196227
</t>
197228
<section title="Assertions and Instance Primitive Types">
198229
<t>

0 commit comments

Comments
 (0)