Skip to content

Commit 7df800b

Browse files
committed
Reverse min/maxContains dependency direction
This fixes the problem where "minContains": 0 effectively un-failed "contains". The observable validation behavior is unchanged.
1 parent d828110 commit 7df800b

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
@@ -719,7 +719,7 @@
719719
<xref target="schema-document">schema object</xref>.
720720
</t>
721721
</section>
722-
<section title="Default Behaviors">
722+
<section title="Default Behaviors" anchor="default-behaviors">
723723
<t>
724724
A missing keyword MUST NOT produce a false assertion result, MUST
725725
NOT produce annotation results, and MUST NOT cause any other schema
@@ -2522,17 +2522,12 @@
25222522
The value of this keyword MUST be a non-negative integer.
25232523
</t>
25242524
<t>
2525-
If "contains" is not present within the same schema object,
2526-
then this keyword has no effect.
2525+
This keyword modifies the behavior of "contains" within the same schema object,
2526+
as described below in the section for that keyword.
25272527
</t>
25282528
<t>
2529-
An instance array or object is valid against "maxContains" in two ways,
2530-
depending on the form of the annotation result of an adjacent
2531-
"contains" keyword. The first way is if
2532-
the annotation result is an array and the length of that array is less than
2533-
or equal to the "maxContains" value. The second way is if the annotation
2534-
result is a boolean "true" and the instance length (number of items or
2535-
properties) is less than or equal to the "maxContains" value.
2529+
Validation MUST always succeed against this keyword.
2530+
The value of this keyword is used as its annotation result.
25362531
</t>
25372532
</section>
25382533

@@ -2541,26 +2536,17 @@
25412536
The value of this keyword MUST be a non-negative integer.
25422537
</t>
25432538
<t>
2544-
If "contains" is not present within the same schema object,
2545-
then this keyword has no effect.
2539+
This keyword modifies the behavior of "contains" within the same schema object,
2540+
as described below in the section for that keyword.
25462541
</t>
25472542
<t>
2548-
An instance array or object is valid against "minContains" in two ways,
2549-
depending on the form of the annotation result of an adjacent
2550-
"contains" keyword. The first way is if
2551-
the annotation result is an array and the length of that array is greater
2552-
than or equal to the "minContains" value. The second way is if the
2553-
annotation result is a boolean "true" and the instance length (number of
2554-
items or properties) is greater than or equal to the "minContains" value.
2543+
Validation MUST always succeed against this keyword.
2544+
The value of this keyword is used as its annotation result.
25552545
</t>
2556-
<t>
2557-
A value of 0 is allowed, but is only useful for setting a range
2558-
of occurrences from 0 to the value of "maxContains". A value of
2559-
0 causes "minContains" and "contains" to always pass validation
2560-
(but validation can still fail against a "maxContains" keyword).
2561-
</t>
2562-
<t>
2563-
Omitting this keyword has the same behavior as a value of 1.
2546+
<t> Per section <xref target="default-behaviors" format="counter"></xref>,
2547+
omitted keywords MUST NOT produce annotation results. However, as described
2548+
in the section for "contains", the absence of this keyword's annotation
2549+
causes "contains" to assume a minimum value of 1.
25642550
</t>
25652551
</section>
25662552

@@ -2569,18 +2555,27 @@
25692555
The value of this keyword MUST be a valid JSON Schema.
25702556
</t>
25712557
<t>
2572-
An array instance is valid against "contains" if at least one of
2573-
its elements is valid against the given schema,
2574-
except when "minContains" is present and has a value of 0, in which
2575-
case an array instance MUST be considered valid against the "contains" keyword,
2576-
even if none of its elements is valid against the given schema.
2558+
This keyword applies its subschema to array elements or object property values.
2559+
</t>
2560+
<t>
2561+
An instance is valid against "contains" if the number of elements or property
2562+
values that are valid against its subschema is with the inclusive range of
2563+
the minimum and (if any) maximum number of occurrences.
25772564
</t>
25782565
<t>
2579-
An object instance is valid against "contains" if at least one of
2580-
its properties is valid against the given schema,
2581-
except when "minContains" is present and has a value of 0, in which
2582-
case an object instance MUST be considered valid against the "contains" keyword,
2583-
even if none of its property values is valid against the given schema.
2566+
The maximum number of occurrences is provided by the "maxContains" keyword
2567+
within the same schema object as "contains". If "maxContains" is absent,
2568+
the maximum number of occurrences MUST be unbounded.
2569+
</t>
2570+
<t>
2571+
The minimum number of occurrences is provided by the "minContains" keyword
2572+
within the same schema object as "contains". If "minContains" is absent,
2573+
the minimum number of occurrences MUST be 1.
2574+
</t>
2575+
<t>
2576+
Implementations MAY implement the dependency on "minContians" and
2577+
"maxContains" by inspecting their values rather than reading annotations
2578+
produced by those keywords.
25842579
</t>
25852580
<t>
25862581
This keyword produces an annotation value which is an array of the
@@ -2593,13 +2588,13 @@
25932588
</t>
25942589
<t>
25952590
This annotation affects the behavior of "unevaluatedItems" in the
2596-
Unevaluated vocabulary, and MAY also be used to implement the
2597-
"minContains" and "maxContains" keywords in the Validation vocabulary.
2591+
Unevaluated vocabulary.
25982592
</t>
25992593
<t>
2600-
The subschema MUST be applied to every array element even after the first
2601-
match has been found, in order to collect annotations for use by other
2602-
keywords. This is to ensure that all possible annotations are collected.
2594+
The subschema MUST be applied to every array element or object property
2595+
value even after the first match has been found, in order to collect
2596+
annotations for use by other keywords. This is to ensure that all possible
2597+
annotations are collected.
26032598
</t>
26042599
</section>
26052600
</section>

0 commit comments

Comments
 (0)