Skip to content

Commit 5c22b30

Browse files
committed
Reverse contains dependency per Karen Etheridge
This fixes the problem where "minContains": 0 effectively un-failed "contains". The observable validation behavior is unchanged. Instead of "minContains" and "maxContains" reading annotations from "contains", "contains" reads annotations from "minContains" and "maxContains" and makes the only assertion decision. This solution was first proposed by Karen Etheridge.
1 parent ead3d31 commit 5c22b30

File tree

1 file changed

+37
-42
lines changed

1 file changed

+37
-42
lines changed

jsonschema-core.xml

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@
733733
<xref target="schema-document">schema object</xref>.
734734
</t>
735735
</section>
736-
<section title="Default Behaviors">
736+
<section title="Default Behaviors" anchor="default-behaviors">
737737
<t>
738738
A missing keyword MUST NOT produce a false assertion result, MUST
739739
NOT produce annotation results, and MUST NOT cause any other schema
@@ -2507,17 +2507,12 @@
25072507
The value of this keyword MUST be a non-negative integer.
25082508
</t>
25092509
<t>
2510-
If "contains" is not present within the same schema object,
2511-
then this keyword has no effect.
2510+
This keyword modifies the behavior of "contains" within the same schema object,
2511+
as described below in the section for that keyword.
25122512
</t>
25132513
<t>
2514-
An instance array or object is valid against "maxContains" in two ways,
2515-
depending on the form of the annotation result of an adjacent
2516-
"contains" keyword. The first way is if
2517-
the annotation result is an array and the length of that array is less than
2518-
or equal to the "maxContains" value. The second way is if the annotation
2519-
result is a boolean "true" and the instance length (number of items or
2520-
properties) is less than or equal to the "maxContains" value.
2514+
Validation MUST always succeed against this keyword.
2515+
The value of this keyword is used as its annotation result.
25212516
</t>
25222517
</section>
25232518

@@ -2526,26 +2521,17 @@
25262521
The value of this keyword MUST be a non-negative integer.
25272522
</t>
25282523
<t>
2529-
If "contains" is not present within the same schema object,
2530-
then this keyword has no effect.
2524+
This keyword modifies the behavior of "contains" within the same schema object,
2525+
as described below in the section for that keyword.
25312526
</t>
25322527
<t>
2533-
An instance array or object is valid against "minContains" in two ways,
2534-
depending on the form of the annotation result of an adjacent
2535-
"contains" keyword. The first way is if
2536-
the annotation result is an array and the length of that array is greater
2537-
than or equal to the "minContains" value. The second way is if the
2538-
annotation result is a boolean "true" and the instance length (number of
2539-
items or properties) is greater than or equal to the "minContains" value.
2528+
Validation MUST always succeed against this keyword.
2529+
The value of this keyword is used as its annotation result.
25402530
</t>
2541-
<t>
2542-
A value of 0 is allowed, but is only useful for setting a range
2543-
of occurrences from 0 to the value of "maxContains". A value of
2544-
0 causes "minContains" and "contains" to always pass validation
2545-
(but validation can still fail against a "maxContains" keyword).
2546-
</t>
2547-
<t>
2548-
Omitting this keyword has the same behavior as a value of 1.
2531+
<t> Per section <xref target="default-behaviors" format="counter"></xref>,
2532+
omitted keywords MUST NOT produce annotation results. However, as described
2533+
in the section for "contains", the absence of this keyword's annotation
2534+
causes "contains" to assume a minimum value of 1.
25492535
</t>
25502536
</section>
25512537

@@ -2554,18 +2540,27 @@
25542540
The value of this keyword MUST be a valid JSON Schema.
25552541
</t>
25562542
<t>
2557-
An array instance is valid against "contains" if at least one of
2558-
its elements is valid against the given schema,
2559-
except when "minContains" is present and has a value of 0, in which
2560-
case an array instance MUST be considered valid against the "contains" keyword,
2561-
even if none of its elements is valid against the given schema.
2543+
This keyword applies its subschema to array elements or object property values.
2544+
</t>
2545+
<t>
2546+
An instance is valid against "contains" if the number of elements or property
2547+
values that are valid against its subschema is with the inclusive range of
2548+
the minimum and (if any) maximum number of occurrences.
25622549
</t>
25632550
<t>
2564-
An object instance is valid against "contains" if at least one of
2565-
its properties is valid against the given schema,
2566-
except when "minContains" is present and has a value of 0, in which
2567-
case an object instance MUST be considered valid against the "contains" keyword,
2568-
even if none of its property values is valid against the given schema.
2551+
The maximum number of occurrences is provided by the "maxContains" keyword
2552+
within the same schema object as "contains". If "maxContains" is absent,
2553+
the maximum number of occurrences MUST be unbounded.
2554+
</t>
2555+
<t>
2556+
The minimum number of occurrences is provided by the "minContains" keyword
2557+
within the same schema object as "contains". If "minContains" is absent,
2558+
the minimum number of occurrences MUST be 1.
2559+
</t>
2560+
<t>
2561+
Implementations MAY implement the dependency on "minContians" and
2562+
"maxContains" by inspecting their values rather than reading annotations
2563+
produced by those keywords.
25692564
</t>
25702565
<t>
25712566
This keyword produces an annotation value which is an array of the
@@ -2578,13 +2573,13 @@
25782573
</t>
25792574
<t>
25802575
This annotation affects the behavior of "unevaluatedItems" in the
2581-
Unevaluated vocabulary, and MAY also be used to implement the
2582-
"minContains" and "maxContains" keywords in the Validation vocabulary.
2576+
Unevaluated vocabulary.
25832577
</t>
25842578
<t>
2585-
The subschema MUST be applied to every array element even after the first
2586-
match has been found, in order to collect annotations for use by other
2587-
keywords. This is to ensure that all possible annotations are collected.
2579+
The subschema MUST be applied to every array element or object property
2580+
value even after the first match has been found, in order to collect
2581+
annotations for use by other keywords. This is to ensure that all possible
2582+
annotations are collected.
25882583
</t>
25892584
</section>
25902585
</section>

0 commit comments

Comments
 (0)