Skip to content

Clarify contains when applying to an empty array #1042

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions jsonschema-core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2360,16 +2360,23 @@
</t>
<t>
An array instance is valid against "contains" if at least one of
its elements is valid against the given schema. Note that when
collecting annotations, the subschema MUST be applied to every
array element even after the first match has been found. This
is to ensure that all possible annotations are collected.
its elements is valid against the given schema. The subschema MUST be
applied to every array element even after the first match has
been found, in order to collect annotations for use by other keywords.
This is to ensure that all possible annotations are collected.
</t>
<t>
Logically, the validation result of applying the value subschema to each
item in the array MUST be ORed with "false", resulting in an overall
validation result.
</t>
<t>
This keyword produces an annotation value which is an array of
the indexes to which this keyword validates successfully when applying
its subschema, in ascending order. The value MAY be a boolean true if the
its subschema, in ascending order. The value MAY be a boolean "true" if the
subschema validated successfully when applied to every index of the instance.
If the instance array this keywords subschema is applicable to is empty,
the annotation value MUST NOT be missing.
</t>
</section>
</section>
Expand Down
32 changes: 18 additions & 14 deletions jsonschema-validation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -408,37 +408,41 @@
<t>
The value of this keyword MUST be a non-negative integer.
</t>
<t>
An array instance is valid against "maxContains" if the number of
elements that are valid against the schema for
<xref target="json-schema">"contains"</xref> is
less than, or equal to, the value of this keyword.
</t>
<t>
If "contains" is not present within the same schema object,
then this keyword has no effect.
</t>
<t>
An array instance is valid against "maxContains" if its
value is less than or equal to, the array length of the annotation
result from an adjacent
<xref target="json-schema">"contains"</xref> keyword where the
annotation is an array, or the length of the instance array
where the annotation is "true".
</t>
</section>

<section title="minContains">
<t>
The value of this keyword MUST be a non-negative integer.
</t>
<t>
An array instance is valid against "minContains" if the number of
elements that are valid against the schema for
<xref target="json-schema">"contains"</xref> is
greater than, or equal to, the value of this keyword.
If "contains" is not present within the same schema object,
then this keyword has no effect.
</t>
<t>
An array instance is valid against "minContains" if its
value is greater than or equal to, the array length of the annotation
result from an adjacent
<xref target="json-schema">"contains"</xref> keyword where the
annotation is an array, or the length of the instance array
where the annotation is "true".
</t>
<t>
A value of 0 is allowed, but is only useful for setting a range
of occurrences from 0 to the value of "maxContains". A value of
0 with no "maxContains" causes "contains" to always pass validation.
</t>
<t>
If "contains" is not present within the same schema object,
then this keyword has no effect.
</t>
<t>
Omitting this keyword has the same behavior as a value of 1.
</t>
Expand Down