Skip to content

Commit ead3d31

Browse files
committed
"minContains"/"maxContains" to applicator vocab
This moves the keywords with minamal changes to make sure the cross-referencing (which no longer goes between two documents) makes sense. A subsequent commit will fix the direction of the dependency.
1 parent 6ec6862 commit ead3d31

File tree

4 files changed

+63
-55
lines changed

4 files changed

+63
-55
lines changed

jsonschema-core.xml

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2122,7 +2122,7 @@
21222122
</t>
21232123
<t>
21242124
"contains", whose behavior is affected by the presence and value of
2125-
"minContains", in the Validation vocabulary
2125+
"minContains"
21262126
</t>
21272127
</list>
21282128
</t>
@@ -2502,6 +2502,53 @@
25022502
</section>
25032503

25042504
<section title="Other Keywords for Applying Subschemas">
2505+
<section title="maxContains">
2506+
<t>
2507+
The value of this keyword MUST be a non-negative integer.
2508+
</t>
2509+
<t>
2510+
If "contains" is not present within the same schema object,
2511+
then this keyword has no effect.
2512+
</t>
2513+
<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.
2521+
</t>
2522+
</section>
2523+
2524+
<section title="minContains">
2525+
<t>
2526+
The value of this keyword MUST be a non-negative integer.
2527+
</t>
2528+
<t>
2529+
If "contains" is not present within the same schema object,
2530+
then this keyword has no effect.
2531+
</t>
2532+
<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.
2540+
</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.
2549+
</t>
2550+
</section>
2551+
25052552
<section title="contains">
25062553
<t>
25072554
The value of this keyword MUST be a valid JSON Schema.

jsonschema-validation.xml

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -404,53 +404,6 @@
404404
Omitting this keyword has the same behavior as a value of false.
405405
</t>
406406
</section>
407-
408-
<section title="maxContains">
409-
<t>
410-
The value of this keyword MUST be a non-negative integer.
411-
</t>
412-
<t>
413-
If "contains" is not present within the same schema object,
414-
then this keyword has no effect.
415-
</t>
416-
<t>
417-
An instance array or object is valid against "maxContains" in two ways,
418-
depending on the form of the annotation result of an adjacent
419-
<xref target="json-schema">"contains"</xref> keyword. The first way is if
420-
the annotation result is an array and the length of that array is less than
421-
or equal to the "maxContains" value. The second way is if the annotation
422-
result is a boolean "true" and the instance length (number of items or
423-
properties) is less than or equal to the "maxContains" value.
424-
</t>
425-
</section>
426-
427-
<section title="minContains">
428-
<t>
429-
The value of this keyword MUST be a non-negative integer.
430-
</t>
431-
<t>
432-
If "contains" is not present within the same schema object,
433-
then this keyword has no effect.
434-
</t>
435-
<t>
436-
An instance array or object is valid against "minContains" in two ways,
437-
depending on the form of the annotation result of an adjacent
438-
<xref target="json-schema">"contains"</xref> keyword. The first way is if
439-
the annotation result is an array and the length of that array is greater
440-
than or equal to the "minContains" value. The second way is if the
441-
annotation result is a boolean "true" and the instance length (number of
442-
items or properties) is greater than or equal to the "minContains" value.
443-
</t>
444-
<t>
445-
A value of 0 is allowed, but is only useful for setting a range
446-
of occurrences from 0 to the value of "maxContains". A value of
447-
0 causes "minContains" and "contains" to always pass validation
448-
(but validation can still fail against a "maxContains" keyword).
449-
</t>
450-
<t>
451-
Omitting this keyword has the same behavior as a value of 1.
452-
</t>
453-
</section>
454407
</section>
455408

456409
<section title="Validation Keywords for Objects">
@@ -1368,8 +1321,8 @@
13681321
<section title="Keywords Moved from Validation to Core">
13691322
<t>
13701323
Several keywords have been moved from this document into the
1371-
<xref target="json-schema">Core Specification</xref> as of this draft, in some
1372-
cases with re-naming or other changes. This affects the following former
1324+
<xref target="json-schema">Core Specification</xref> starting with draft 2019-09,
1325+
in some cases with re-naming or other changes. This affects the following former
13731326
validation keywords:
13741327
<list style="hanging">
13751328
<t hangText='"definitions"'>
@@ -1393,6 +1346,10 @@
13931346
For this reason, they are better defined as a generic mechanism on which
13941347
validation, hyper-schema, and extension vocabularies can all be based.
13951348
</t>
1349+
<t hangText='"maxContains", "minContains"'>
1350+
These keywords modify the behavior of "contains", and are therefore
1351+
grouped with it in the applicator vocabulary.
1352+
</t>
13961353
<t hangText='"dependencies"'>
13971354
This keyword had two different modes of behavior, which made it
13981355
relatively challenging to implement and reason about.

meta/applicator.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
"properties": {
1212
"prefixItems": { "$ref": "#/$defs/schemaArray" },
1313
"items": { "$dynamicRef": "#meta" },
14+
"maxContains": { "$ref": "#/$defs/nonNegativeInteger" },
15+
"minContains": {
16+
"$ref": "#/$defs/nonNegativeInteger",
17+
"default": 1
18+
},
1419
"contains": { "$dynamicRef": "#meta" },
1520
"additionalProperties": { "$dynamicRef": "#meta" },
1621
"properties": {
@@ -48,6 +53,10 @@
4853
"not": { "$dynamicRef": "#meta" }
4954
},
5055
"$defs": {
56+
"nonNegativeInteger": {
57+
"type": "integer",
58+
"minimum": 0
59+
},
5160
"schemaArray": {
5261
"type": "array",
5362
"minItems": 1,

meta/validation.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@
5353
"type": "boolean",
5454
"default": false
5555
},
56-
"maxContains": { "$ref": "#/$defs/nonNegativeInteger" },
57-
"minContains": {
58-
"$ref": "#/$defs/nonNegativeInteger",
59-
"default": 1
60-
},
6156
"maxProperties": { "$ref": "#/$defs/nonNegativeInteger" },
6257
"minProperties": { "$ref": "#/$defs/nonNegativeIntegerDefault0" },
6358
"required": { "$ref": "#/$defs/stringArray" },

0 commit comments

Comments
 (0)