Skip to content

Commit b02cc10

Browse files
authored
Merge pull request #1577 from json-schema-org/gregsdennis/validation-not-required
keywords only exhibit the behaviors they're defined with
2 parents 788dcbb + 6272ae8 commit b02cc10

File tree

2 files changed

+74
-19
lines changed

2 files changed

+74
-19
lines changed

specs/jsonschema-core.md

+58-18
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,18 @@ Additional schema keywords MAY be defined by any entity. Save for explicit
394394
agreement, schema authors SHALL NOT expect these additional keywords to be
395395
supported by implementations that do not explicitly document such support.
396396

397+
Extension keywords MUST NOT directly modify the operation of keywords defined by
398+
this document or the companion JSON Schema Validation specificiation, and SHOULD
399+
NOT directly modify the operation of keywords defined by other extension
400+
documents.[^11]
401+
402+
[^11]: JSON Schema currently does not have a namespacing mechanism, which would
403+
allow multiple extensions to define the same keyword differently while also
404+
giving the schema author the ability to declare which definition is intended.
405+
Such a feature is planned for future releases. See the
406+
[Vocabularies / Extensions project](https://github.com/orgs/json-schema-org/projects/28/views/2)
407+
in GitHub for more information.
408+
397409
Implementations MAY provide the ability to register or load handlers for
398410
keywords that they do not support directly. The exact mechanism for registering
399411
and implementing such handlers is implementation-dependent.
@@ -415,20 +427,40 @@ keywords MUST NOT begin with this prefix.
415427
Implementations MUST refuse to evaluate schemas which contain keywords which
416428
they do not know how to process or explicitly choose not to process.
417429

418-
## Keyword Behaviors
430+
## Keyword Behaviors {#keyword-behaviors}
419431

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.
432+
JSON Schema keywords may exhibit one or more behaviors. This specification
433+
defines three such behaviors[^7]:
434+
435+
- Assertions validate that an instance satisfies constraints, producing a
436+
boolean result: `true` if the constraints are satisfied; `false` otherwise.
437+
- Annotations attach information to instance locations that applications may use
438+
in any way they see fit.
439+
- Applicators apply subschemas to parts of the instance and combine their
440+
results.
441+
442+
[^7]: This specification also defines several operational directive keywords,
443+
such as `$id` and `$schema`, which do not exhibit these behaviors. Instead,
444+
these keywords provide metadata that instruct implementations on how to
445+
interpret and process the schema.
425446

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

453+
Implementations SHOULD NOT add unspecified behaviors to keywords.
454+
455+
For the purposes of this document, an instance "validating against a keyword"
456+
means that the keyword produces an assertion result of `true` if the instance
457+
satisfies the given constraint; otherwise an assertion result of `false` is
458+
produced.
459+
460+
<!-- The next two paragraphs and the following section seem to have more to
461+
do with schema evaluation than keywords specifically. I'd like to move them out
462+
of the "keyword behaviors" h2, but will do so separately. [TODO: GD] -->
463+
432464
Evaluating an instance against a schema involves processing all of the keywords
433465
in the schema against the appropriate locations within the instance. Typically,
434466
applicator keywords are processed until a schema object with no applicators (and
@@ -581,11 +613,19 @@ the keyword's value. Alternatively, an applicator may refer to a schema
581613
elsewhere in the same schema document, or in a different one. The mechanism for
582614
identifying such referenced schemas is defined by the keyword.
583615

584-
Applicator keywords also define how subschema or referenced schema boolean
585-
[assertion](#assertions) results are modified and/or combined to produce the
586-
boolean result of the applicator. Applicators may apply any boolean logic
587-
operation to the assertion results of subschemas, but MUST NOT introduce new
588-
assertion conditions of their own.
616+
Applicator keywords also behave as assertions, using the assertion results of
617+
each subschema or referenced schema of the keyword. These boolean results are
618+
modified (e.g. the `not` keyword negates its subschema's assertion) and/or
619+
combined (e.g. `allOf` takes the conjunction of its subschemas' assertions) to
620+
produce the boolean result of the applicator. Applicators may apply any boolean
621+
logic operation to the assertion results of subschemas, but SHOULD NOT introduce
622+
new assertion conditions of their own.[^2]
623+
624+
[^2]: It is recommended that keywords have a single resposibility. An example of
625+
this in action is the separation between `properties`, which verifies object
626+
property values have the right data _if_ they exist, and `required`, which
627+
verifies that object properties exist. Separating these concerns allows for more
628+
reusable components.
589629

590630
[Annotation](#annotations) results from subschemas are preserved in accordance
591631
with {{collect}} so that applications can decide how to interpret multiple
@@ -1491,8 +1531,8 @@ operators can contact the owner of a potentially misbehaving script.
14911531

14921532
## Keywords for Applying Subschemas
14931533

1494-
This section defines a set of keywords that enable schema combinations and
1495-
composition.
1534+
This section defines a set of applicator keywords that enable schema
1535+
combinations and composition.
14961536

14971537
### Keywords for Applying Subschemas in Place {#in-place}
14981538

@@ -1752,8 +1792,8 @@ The value of this keyword MUST be a non-negative integer.
17521792
This keyword modifies the behavior of `contains` within the same schema object,
17531793
as described below in the section for that keyword.
17541794

1755-
Validation MUST always succeed against this keyword. The value of this keyword
1756-
is used as its annotation result.
1795+
This keyword produces no assertion result. The value of this keyword is used as
1796+
its annotation result.
17571797

17581798
##### `minContains`
17591799

@@ -1762,8 +1802,8 @@ The value of this keyword MUST be a non-negative integer.
17621802
This keyword modifies the behavior of `contains` within the same schema object,
17631803
as described below in the section for that keyword.
17641804

1765-
Validation MUST always succeed against this keyword. The value of this keyword
1766-
is used as its annotation result.
1805+
This keyword has no assertion behavior. The value of this keyword is used as
1806+
its annotation result.
17671807

17681808
Per {{default-behaviors}}, omitted keywords MUST NOT produce annotation results.
17691809
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 evaluation 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
@@ -652,7 +667,7 @@ structures: first the header, and then the payload. Since the JWT media type
652667
ensures that the JWT can be represented in a JSON string, there is no need for
653668
further encoding or decoding.
654669

655-
## Keywords for Basic Meta-Data Annotations
670+
## Keywords for Basic Meta-Data Annotations {#annotations}
656671

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

0 commit comments

Comments
 (0)