Skip to content

Commit de8ed30

Browse files
committed
keywords only exhibit the behaviors they're defined with
1 parent 8af8969 commit de8ed30

File tree

2 files changed

+56
-19
lines changed

2 files changed

+56
-19
lines changed

specs/jsonschema-core.md

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -415,20 +415,37 @@ keywords MUST NOT begin with this prefix.
415415
Implementations MUST refuse to evaluate schemas which contain keywords which
416416
they do not know how to process or explicitly choose not to process.
417417

418-
## Keyword Behaviors
418+
## Keyword Behaviors {#keyword-behaviors}
419419

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

426-
Extension keywords SHOULD stay within these categories, keeping in mind that
430+
Extension keywords SHOULD be defined using these behaviors, keeping in mind that
427431
annotations in particular are extremely flexible. Complex behavior is usually
428432
better delegated to applications on the basis of annotation data than
429433
implemented directly as schema keywords. However, extension keywords MAY define
430434
other behaviors for specialized purposes.
431435

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

572-
Applicator keywords also define how subschema or referenced schema boolean
573-
[assertion](#assertions) results are modified and/or combined to produce the
574-
boolean result of the applicator. Applicators may apply any boolean logic
575-
operation to the assertion results of subschemas, but MUST NOT introduce new
576-
assertion conditions of their own.
589+
Applicator keywords also behave as assertions by defining how subschema or
590+
referenced schema boolean [assertion](#assertions) results are modified and/or
591+
combined to produce the boolean result of the applicator. Applicators may apply
592+
any boolean logic operation to the assertion results of subschemas, but MUST NOT
593+
introduce new assertion conditions of their own.
577594

578595
[Annotation](#annotations) results from subschemas are preserved in accordance
579596
with {{collect}} so that applications can decide how to interpret multiple
@@ -1001,11 +1018,16 @@ identified schema. Its results are the results of the referenced schema.[^5]
10011018
[^5]: Note that this definition of how the results are determined means that
10021019
other keywords can appear alongside of `$ref` in the same schema object.
10031020

1021+
The value of the `$ref` keyword MUST be a string which is an IRI reference.
10041022
The value of the `$ref` keyword MUST be a string which is an IRI reference.
10051023
Resolved against the current IRI base, it produces the IRI of the schema to
10061024
apply. This resolution is safe to perform on schema load, as the process of
10071025
evaluating an instance cannot change how the reference resolves.
10081026

1027+
The resolved IRI produced by `$ref` is not necessarily a network locator, only
1028+
an identifier. A schema need not be downloadable from the address if it is a
1029+
network-addressable URL. Implementations which can access the network SHOULD
1030+
default to operating offline.
10091031
The resolved IRI produced by `$ref` is not necessarily a network locator, only
10101032
an identifier. A schema need not be downloadable from the address if it is a
10111033
network-addressable URL. Implementations which can access the network SHOULD
@@ -1476,8 +1498,8 @@ operators can contact the owner of a potentially misbehaving script.
14761498

14771499
## Keywords for Applying Subschemas
14781500

1479-
This section defines a set of keywords that enable schema combinations and
1480-
composition.
1501+
This section defines a set of applicator keywords that enable schema
1502+
combinations and composition.
14811503

14821504
### Keywords for Applying Subschemas in Place {#in-place}
14831505

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

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

17431765
##### `minContains`
17441766

@@ -1747,8 +1769,8 @@ The value of this keyword MUST be a non-negative integer.
17471769
This keyword modifies the behavior of `contains` within the same schema object,
17481770
as described below in the section for that keyword.
17491771

1750-
Validation MUST always succeed against this keyword. The value of this keyword
1751-
is used as its annotation result.
1772+
This keyword produces no assertion result. The value of this keyword is used as
1773+
its annotation result.
17521774

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

specs/jsonschema-validation.md

Lines changed: 16 additions & 1 deletion
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
@@ -642,7 +657,7 @@ structures: first the header, and then the payload. Since the JWT media type
642657
ensures that the JWT can be represented in a JSON string, there is no need for
643658
further encoding or decoding.
644659

645-
## Keywords for Basic Meta-Data Annotations
660+
## Keywords for Basic Meta-Data Annotations {#annotations}
646661

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

0 commit comments

Comments
 (0)