Skip to content

Commit 803ce7d

Browse files
authored
Merge pull request #1042 from Relequestual/issue/942-clarify-contains
Clarify contains when applying to an empty array
2 parents 2c7d4bc + 3cf7cb8 commit 803ce7d

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

jsonschema-core.xml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,16 +2360,23 @@
23602360
</t>
23612361
<t>
23622362
An array instance is valid against "contains" if at least one of
2363-
its elements is valid against the given schema. Note that when
2364-
collecting annotations, the subschema MUST be applied to every
2365-
array element even after the first match has been found. This
2366-
is to ensure that all possible annotations are collected.
2363+
its elements is valid against the given schema. The subschema MUST be
2364+
applied to every array element even after the first match has
2365+
been found, in order to collect annotations for use by other keywords.
2366+
This is to ensure that all possible annotations are collected.
2367+
</t>
2368+
<t>
2369+
Logically, the validation result of applying the value subschema to each
2370+
item in the array MUST be ORed with "false", resulting in an overall
2371+
validation result.
23672372
</t>
23682373
<t>
23692374
This keyword produces an annotation value which is an array of
23702375
the indexes to which this keyword validates successfully when applying
2371-
its subschema, in ascending order. The value MAY be a boolean true if the
2376+
its subschema, in ascending order. The value MAY be a boolean "true" if the
23722377
subschema validated successfully when applied to every index of the instance.
2378+
If the instance array this keywords subschema is applicable to is empty,
2379+
the annotation value MUST NOT be missing.
23732380
</t>
23742381
</section>
23752382
</section>

jsonschema-validation.xml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -408,37 +408,41 @@
408408
<t>
409409
The value of this keyword MUST be a non-negative integer.
410410
</t>
411-
<t>
412-
An array instance is valid against "maxContains" if the number of
413-
elements that are valid against the schema for
414-
<xref target="json-schema">"contains"</xref> is
415-
less than, or equal to, the value of this keyword.
416-
</t>
417411
<t>
418412
If "contains" is not present within the same schema object,
419413
then this keyword has no effect.
420414
</t>
415+
<t>
416+
An array instance is valid against "maxContains" if its
417+
value is less than or equal to, the array length of the annotation
418+
result from an adjacent
419+
<xref target="json-schema">"contains"</xref> keyword where the
420+
annotation is an array, or the length of the instance array
421+
where the annotation is "true".
422+
</t>
421423
</section>
422424

423425
<section title="minContains">
424426
<t>
425427
The value of this keyword MUST be a non-negative integer.
426428
</t>
427429
<t>
428-
An array instance is valid against "minContains" if the number of
429-
elements that are valid against the schema for
430-
<xref target="json-schema">"contains"</xref> is
431-
greater than, or equal to, the value of this keyword.
430+
If "contains" is not present within the same schema object,
431+
then this keyword has no effect.
432+
</t>
433+
<t>
434+
An array instance is valid against "minContains" if its
435+
value is greater than or equal to, the array length of the annotation
436+
result from an adjacent
437+
<xref target="json-schema">"contains"</xref> keyword where the
438+
annotation is an array, or the length of the instance array
439+
where the annotation is "true".
432440
</t>
433441
<t>
434442
A value of 0 is allowed, but is only useful for setting a range
435443
of occurrences from 0 to the value of "maxContains". A value of
436444
0 with no "maxContains" causes "contains" to always pass validation.
437445
</t>
438-
<t>
439-
If "contains" is not present within the same schema object,
440-
then this keyword has no effect.
441-
</t>
442446
<t>
443447
Omitting this keyword has the same behavior as a value of 1.
444448
</t>

0 commit comments

Comments
 (0)