-
-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
keywords only exhibit the behaviors they're defined with #1577
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -410,20 +410,37 @@ keywords MUST NOT begin with this prefix. | |
Implementations MUST refuse to evaluate schemas which contain keywords which | ||
they do not know how to process or explicitly choose not to process. | ||
|
||
## Keyword Behaviors | ||
## Keyword Behaviors {#keyword-behaviors} | ||
|
||
JSON Schema keywords fall into several general behavior categories. Assertions | ||
validate that an instance satisfies constraints, producing a boolean result. | ||
Annotations attach information that applications may use in any way they see | ||
fit. Applicators apply subschemas to parts of the instance and combine their | ||
results. | ||
JSON Schema keywords may exhibit one or more behaviors. This specification | ||
defines three such behaviors: | ||
|
||
- Assertions validate that an instance satisfies constraints, producing a | ||
boolean result: `true` if the constraints are satisfied; `false` otherwise. | ||
- Annotations attach information that applications may use in any way they see | ||
fit. | ||
- Applicators apply subschemas to parts of the instance and combine their | ||
results. | ||
|
||
Extension keywords SHOULD stay within these categories, keeping in mind that | ||
Extension keywords SHOULD be defined using these behaviors, keeping in mind that | ||
annotations in particular are extremely flexible. Complex behavior is usually | ||
better delegated to applications on the basis of annotation data than | ||
implemented directly as schema keywords. However, extension keywords MAY define | ||
other behaviors for specialized purposes. | ||
|
||
Keywords which are not defined to exhibit a particular behavior MUST NOT affect | ||
that aspect of evalution. For example, a keyword which does not act as an | ||
gregsdennis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assertion MUST NOT affect the validation result. | ||
|
||
For the purposes of this document, an instance "validating against a keyword" | ||
means that the keyword produces an assertion result of `true` if the instance | ||
satisfies the given constraint; otherwise an assertion result of `false` is | ||
produced. | ||
|
||
<!-- The next two paragraphs and the following section seem to have to more to | ||
gregsdennis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
do with schema evaluation than keywords specifically. I'd like to move them out | ||
of the "keyword behaviors" h2, but will do so separately. [TODO: GD] --> | ||
|
||
Evaluating an instance against a schema involves processing all of the keywords | ||
in the schema against the appropriate locations within the instance. Typically, | ||
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 | |
elsewhere in the same schema document, or in a different one. The mechanism for | ||
identifying such referenced schemas is defined by the keyword. | ||
|
||
Applicator keywords also define how subschema or referenced schema boolean | ||
[assertion](#assertions) results are modified and/or combined to produce the | ||
boolean result of the applicator. Applicators may apply any boolean logic | ||
operation to the assertion results of subschemas, but MUST NOT introduce new | ||
assertion conditions of their own. | ||
Applicator keywords also behave as assertions by defining how subschema or | ||
referenced schema boolean [assertion](#assertions) results are modified and/or | ||
combined to produce the boolean result of the applicator. Applicators may apply | ||
any boolean logic operation to the assertion results of subschemas, but MUST NOT | ||
introduce new assertion conditions of their own. | ||
Comment on lines
+587
to
+588
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm not following this. What is this trying to say? What are we protecting against be forbidding it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That text was already there. It's just saying that applicator assertions can only be combinatorial on their subschemas. For instance I think this is a simplicity guard, kind of a JSON Schema version of SRP. I suppose this means something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jdesrosiers what do you think of relaxing this to a SHOULD, or maybe even an informative note suggesting simplicity over complexity? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's unnecessary for that to be a constraint. Your
Yes. I think that's a great idea. |
||
|
||
[Annotation](#annotations) results from subschemas are preserved in accordance | ||
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] | |
[^5]: Note that this definition of how the results are determined means that | ||
other keywords can appear alongside of `$ref` in the same schema object. | ||
|
||
The value of the `$ref` keyword MUST be a string which is a IRI reference. | ||
The value of the `$ref` keyword MUST be a string which is an IRI reference. | ||
Resolved against the current IRI base, it produces the IRI of the schema to | ||
apply. This resolution is safe to perform on schema load, as the process of | ||
evaluating an instance cannot change how the reference resolves. | ||
|
||
The resolved IRI produced by `$ref` is not necessarily a network | ||
locator, only an identifier. A schema need not be downloadable from the address | ||
if it is a network-addressable URL. Implementations which can access the network | ||
SHOULD default to operating offline. | ||
The resolved IRI produced by `$ref` is not necessarily a network locator, only | ||
an identifier. A schema need not be downloadable from the address if it is a | ||
network-addressable URL. Implementations which can access the network SHOULD | ||
default to operating offline. | ||
|
||
##### Dynamic References with `$dynamicRef` {#dynamic-ref} | ||
|
||
The `$dynamicRef` keyword is an applicator that allows for deferring the full | ||
resolution until runtime, at which point it is resolved each time it is | ||
encountered while evaluating an instance. | ||
encountered while evaluating an instance. Its results are the results of the | ||
referenced schema. | ||
|
||
Together with `$dynamicAnchor`, `$dynamicRef` implements a cooperative extension | ||
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. | |
|
||
## Keywords for Applying Subschemas | ||
|
||
This section defines a set of keywords that enable schema combinations and | ||
composition. | ||
This section defines a set of applicator keywords that enable schema | ||
combinations and composition. | ||
|
||
### Keywords for Applying Subschemas in Place {#in-place} | ||
|
||
|
@@ -1727,8 +1745,8 @@ The value of this keyword MUST be a non-negative integer. | |
This keyword modifies the behavior of `contains` within the same schema object, | ||
as described below in the section for that keyword. | ||
|
||
Validation MUST always succeed against this keyword. The value of this keyword | ||
is used as its annotation result. | ||
This keyword produces no assertion result. The value of this keyword is used as | ||
its annotation result. | ||
|
||
##### `minContains` | ||
|
||
|
@@ -1737,8 +1755,8 @@ The value of this keyword MUST be a non-negative integer. | |
This keyword modifies the behavior of `contains` within the same schema object, | ||
as described below in the section for that keyword. | ||
|
||
Validation MUST always succeed against this keyword. The value of this keyword | ||
is used as its annotation result. | ||
This keyword produces no assertion result. The value of this keyword is used as | ||
its annotation result. | ||
|
||
Per {{default-behaviors}}, omitted keywords MUST NOT produce annotation results. | ||
However, as described in {{contains}}, the absence of this keyword's annotation | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to say that all keyword behaviors in the specification are in these three categories, but the spec defines other behaviors for e.g.
$id
and$anchor
/$dynamicAnchor
. And$schema
... exists.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is an interesting point. I was thinking that these keywords don't exhibit a behavior so much as they are merely informative, like
maxContains
would be tocontains
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great point! My implementation doesn't even treat those as keywords. They're meta-data used to process the schema, but they're not directly part of the validation/annotation process. So, I wouldn't consider them similar to
maxContains
that is involved in validation.I'm not sure what I'd suggest, but I think something needs to be called that these aren't normal keywords.