Skip to content

Commit 969dc42

Browse files
committed
keywords only exhibit the behaviors they're defined with
1 parent 258d721 commit 969dc42

File tree

2 files changed

+58
-25
lines changed

2 files changed

+58
-25
lines changed

specs/jsonschema-core.md

+42-24
Original file line numberDiff line numberDiff line change
@@ -410,20 +410,37 @@ keywords MUST NOT begin with this prefix.
410410
Implementations MUST refuse to evaluate schemas which contain keywords which
411411
they do not know how to process or explicitly choose not to process.
412412

413-
## Keyword Behaviors
413+
## Keyword Behaviors {#keyword-behaviors}
414414

415-
JSON Schema keywords fall into several general behavior categories. Assertions
416-
validate that an instance satisfies constraints, producing a boolean result.
417-
Annotations attach information that applications may use in any way they see
418-
fit. Applicators apply subschemas to parts of the instance and combine their
419-
results.
415+
JSON Schema keywords may exhibit one or more behaviors. This specification
416+
defines three such behaviors:
417+
418+
- Assertions validate that an instance satisfies constraints, producing a
419+
boolean result: `true` if the constraints are satisfied; `false` otherwise.
420+
- Annotations attach information that applications may use in any way they see
421+
fit.
422+
- Applicators apply subschemas to parts of the instance and combine their
423+
results.
420424

421-
Extension keywords SHOULD stay within these categories, keeping in mind that
425+
Extension keywords SHOULD be defined using these behaviors, keeping in mind that
422426
annotations in particular are extremely flexible. Complex behavior is usually
423427
better delegated to applications on the basis of annotation data than
424428
implemented directly as schema keywords. However, extension keywords MAY define
425429
other behaviors for specialized purposes.
426430

431+
Keywords which are not defined to exhibit a particular behavior MUST NOT affect
432+
that aspect of evalution. For example, a keyword which does not act as an
433+
assertion MUST NOT affect the validation result.
434+
435+
For the purposes of this document, an instance "validating against a keyword"
436+
means that the keyword produces an assertion result of `true` if the instance
437+
satisfies the given constraint; otherwise an assertion result of `false` is
438+
produced.
439+
440+
<!-- The next two paragraphs and the following section seem to have to more to
441+
do with schema evaluation than keywords specifically. I'd like to move them out
442+
of the "keyword behaviors" h2, but will do so separately. [TODO: GD] -->
443+
427444
Evaluating an instance against a schema involves processing all of the keywords
428445
in the schema against the appropriate locations within the instance. Typically,
429446
applicator keywords are processed until a schema object with no applicators (and
@@ -564,11 +581,11 @@ the keyword's value. Alternatively, an applicator may refer to a schema
564581
elsewhere in the same schema document, or in a different one. The mechanism for
565582
identifying such referenced schemas is defined by the keyword.
566583

567-
Applicator keywords also define how subschema or referenced schema boolean
568-
[assertion](#assertions) results are modified and/or combined to produce the
569-
boolean result of the applicator. Applicators may apply any boolean logic
570-
operation to the assertion results of subschemas, but MUST NOT introduce new
571-
assertion conditions of their own.
584+
Applicator keywords also behave as assertions by defining how subschema or
585+
referenced schema boolean [assertion](#assertions) results are modified and/or
586+
combined to produce the boolean result of the applicator. Applicators may apply
587+
any boolean logic operation to the assertion results of subschemas, but MUST NOT
588+
introduce new assertion conditions of their own.
572589

573590
[Annotation](#annotations) results from subschemas are preserved in accordance
574591
with {{collect}} so that applications can decide how to interpret multiple
@@ -993,21 +1010,22 @@ identified schema. Its results are the results of the referenced schema.[^5]
9931010
[^5]: Note that this definition of how the results are determined means that
9941011
other keywords can appear alongside of `$ref` in the same schema object.
9951012

996-
The value of the `$ref` keyword MUST be a string which is a IRI reference.
1013+
The value of the `$ref` keyword MUST be a string which is an IRI reference.
9971014
Resolved against the current IRI base, it produces the IRI of the schema to
9981015
apply. This resolution is safe to perform on schema load, as the process of
9991016
evaluating an instance cannot change how the reference resolves.
10001017

1001-
The resolved IRI produced by `$ref` is not necessarily a network
1002-
locator, only an identifier. A schema need not be downloadable from the address
1003-
if it is a network-addressable URL. Implementations which can access the network
1004-
SHOULD default to operating offline.
1018+
The resolved IRI produced by `$ref` is not necessarily a network locator, only
1019+
an identifier. A schema need not be downloadable from the address if it is a
1020+
network-addressable URL. Implementations which can access the network SHOULD
1021+
default to operating offline.
10051022

10061023
##### Dynamic References with `$dynamicRef` {#dynamic-ref}
10071024

10081025
The `$dynamicRef` keyword is an applicator that allows for deferring the full
10091026
resolution until runtime, at which point it is resolved each time it is
1010-
encountered while evaluating an instance.
1027+
encountered while evaluating an instance. Its results are the results of the
1028+
referenced schema.
10111029

10121030
Together with `$dynamicAnchor`, `$dynamicRef` implements a cooperative extension
10131031
mechanism that is primarily useful to to create open schemas, where
@@ -1465,8 +1483,8 @@ operators can contact the owner of a potentially misbehaving script.
14651483

14661484
## Keywords for Applying Subschemas
14671485

1468-
This section defines a set of keywords that enable schema combinations and
1469-
composition.
1486+
This section defines a set of applicator keywords that enable schema
1487+
combinations and composition.
14701488

14711489
### Keywords for Applying Subschemas in Place {#in-place}
14721490

@@ -1727,8 +1745,8 @@ The value of this keyword MUST be a non-negative integer.
17271745
This keyword modifies the behavior of `contains` within the same schema object,
17281746
as described below in the section for that keyword.
17291747

1730-
Validation MUST always succeed against this keyword. The value of this keyword
1731-
is used as its annotation result.
1748+
This keyword produces no assertion result. The value of this keyword is used as
1749+
its annotation result.
17321750

17331751
##### `minContains`
17341752

@@ -1737,8 +1755,8 @@ The value of this keyword MUST be a non-negative integer.
17371755
This keyword modifies the behavior of `contains` within the same schema object,
17381756
as described below in the section for that keyword.
17391757

1740-
Validation MUST always succeed against this keyword. The value of this keyword
1741-
is used as its annotation result.
1758+
This keyword produces no assertion result. The value of this keyword is used as
1759+
its annotation result.
17421760

17431761
Per {{default-behaviors}}, omitted keywords MUST NOT produce annotation results.
17441762
However, as described in {{contains}}, the absence of this keyword's annotation

specs/jsonschema-validation.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ information. The {{format}} keyword is intended primarily as an annotation, but
6262
can optionally be used as an assertion. The {{content}} keywords are annotations
6363
for working with documents embedded as JSON strings.
6464

65+
## Keyword Behaviors
66+
67+
The keywords defined by this document exhibit one or more behaviors as defined by
68+
the [JSON Schema Core Specification](./jsonschema-core.md#keyword-behaviors).
69+
70+
Keywords which are not defined to exhibit a particular behavior MUST NOT affect
71+
that aspect of the evalution outcome. In particular, the keywords defined in
72+
{{annotations}} produce no assertion result and therefore are not considered
73+
during validation.
74+
75+
For the purposes of this document, an instance "validating against a keyword"
76+
means that the keyword produces an assertion result of `true` if the instance
77+
satisfies the given constraint; otherwise an assertion result of `false` is
78+
produced.
79+
6580
## Interoperability Considerations
6681

6782
### Validation of String Instances
@@ -614,7 +629,7 @@ structures: first the header, and then the payload. Since the JWT media type
614629
ensures that the JWT can be represented in a JSON string, there is no need for
615630
further encoding or decoding.
616631

617-
## Keywords for Basic Meta-Data Annotations
632+
## Keywords for Basic Meta-Data Annotations {#annotations}
618633

619634
These general-purpose annotation keywords provide commonly used information for
620635
documentation and user interface display purposes. They are not intended to form

0 commit comments

Comments
 (0)