Skip to content

Commit fb37908

Browse files
authored
Merge pull request #1312 from handrews/mmcontains
Reverse contains dependency per Karen Etheridge
2 parents 6ec6862 + 5c22b30 commit fb37908

File tree

4 files changed

+74
-71
lines changed

4 files changed

+74
-71
lines changed

jsonschema-core.xml

Lines changed: 59 additions & 17 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
@@ -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,23 +2502,65 @@
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+
This keyword modifies the behavior of "contains" within the same schema object,
2511+
as described below in the section for that keyword.
2512+
</t>
2513+
<t>
2514+
Validation MUST always succeed against this keyword.
2515+
The value of this keyword is used as its annotation result.
2516+
</t>
2517+
</section>
2518+
2519+
<section title="minContains">
2520+
<t>
2521+
The value of this keyword MUST be a non-negative integer.
2522+
</t>
2523+
<t>
2524+
This keyword modifies the behavior of "contains" within the same schema object,
2525+
as described below in the section for that keyword.
2526+
</t>
2527+
<t>
2528+
Validation MUST always succeed against this keyword.
2529+
The value of this keyword is used as its annotation result.
2530+
</t>
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.
2535+
</t>
2536+
</section>
2537+
25052538
<section title="contains">
25062539
<t>
25072540
The value of this keyword MUST be a valid JSON Schema.
25082541
</t>
25092542
<t>
2510-
An array instance is valid against "contains" if at least one of
2511-
its elements is valid against the given schema,
2512-
except when "minContains" is present and has a value of 0, in which
2513-
case an array instance MUST be considered valid against the "contains" keyword,
2514-
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.
2549+
</t>
2550+
<t>
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.
25152554
</t>
25162555
<t>
2517-
An object instance is valid against "contains" if at least one of
2518-
its properties is valid against the given schema,
2519-
except when "minContains" is present and has a value of 0, in which
2520-
case an object instance MUST be considered valid against the "contains" keyword,
2521-
even if none of its property values is valid against the given schema.
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.
25222564
</t>
25232565
<t>
25242566
This keyword produces an annotation value which is an array of the
@@ -2531,13 +2573,13 @@
25312573
</t>
25322574
<t>
25332575
This annotation affects the behavior of "unevaluatedItems" in the
2534-
Unevaluated vocabulary, and MAY also be used to implement the
2535-
"minContains" and "maxContains" keywords in the Validation vocabulary.
2576+
Unevaluated vocabulary.
25362577
</t>
25372578
<t>
2538-
The subschema MUST be applied to every array element even after the first
2539-
match has been found, in order to collect annotations for use by other
2540-
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.
25412583
</t>
25422584
</section>
25432585
</section>

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)