Skip to content

Commit 378aae2

Browse files
authored
Merge pull request #925 from handrews/items
Split "prefixItems" from "items", drop "additionalItems", make "unevaluatedItems" respect "contains"
2 parents 339b46c + cfa0b72 commit 378aae2

File tree

2 files changed

+56
-71
lines changed

2 files changed

+56
-71
lines changed

jsonschema-core.xml

+54-64
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@
703703
an alternate implementation producing the same behavior is available.
704704
Keywords of this sort SHOULD describe reasonable alternate approaches
705705
when appropriate. This approach is demonstrated by the
706-
"<xref target="additionalItems" format="title"/>" and
706+
"<xref target="items" format="title"/>" and
707707
"<xref target="additionalProperties" format="title"/>" keywords in this
708708
document.
709709
</t>
@@ -931,7 +931,7 @@
931931
{
932932
"title": "Feature list",
933933
"type": "array",
934-
"items": [
934+
"prefixItems": [
935935
{
936936
"title": "Feature A",
937937
"properties": {
@@ -2143,11 +2143,11 @@
21432143
"additionalProperties" and itself
21442144
</t>
21452145
<t>
2146-
"additionalItems", whose behavior is defined in terms of "items"
2146+
"items", whose behavior is defined in terms of "prefixItems"
21472147
</t>
21482148
<t>
21492149
"unevaluatedItems", whose behavior is defined in terms of annotations
2150-
from "items", "additionalItems" and itself
2150+
from "prefixItems", "items", "contains", and itself
21512151
</t>
21522152
</list>
21532153
</t>
@@ -2326,61 +2326,53 @@
23262326
properties and array items, and combining their results.
23272327
</t>
23282328
<section title="Keywords for Applying Subschemas to Arrays">
2329-
<section title="items">
2329+
<section title="prefixItems">
23302330
<t>
2331-
The value of "items" MUST be either a valid JSON Schema or
2332-
an array of valid JSON Schemas.
2331+
The value of "prefixItems" MUST be an array of valid JSON Schemas.
23332332
</t>
23342333
<t>
2335-
If "items" is a schema, validation succeeds if all elements
2336-
in the array successfully validate against that schema.
2337-
</t>
2338-
<t>
2339-
If "items" is an array of schemas, validation succeeds if
2340-
each element of the instance validates against the schema at the
2341-
same position, if any.
2334+
Validation succeeds if each element of the instance validates
2335+
against the schema at the same position, if any. This keyword
2336+
does not constrain the length of the array. If the array is longer
2337+
than this keyword's value, this keyword validates only the
2338+
prefix of matching length.
23422339
</t>
23432340
<t>
23442341
This keyword produces an annotation value which is the largest
23452342
index to which this keyword applied a subschema. The value
23462343
MAY be a boolean true if a subschema was applied to every
2347-
index of the instance, such as when "items" is a schema.
2348-
</t>
2349-
<t>
2350-
Annotation results for "items" keywords from multiple
2351-
schemas applied to the same instance location are combined
2352-
by setting the combined result to true if any of the values
2353-
are true, and otherwise retaining the largest numerical value.
2344+
index of the instance, such as is produced by the "items" keyword.
2345+
This annotation affects the behavior of "items" and "unevaluatedItems".
23542346
</t>
23552347
<t>
23562348
Omitting this keyword has the same assertion behavior as
2357-
an empty schema.
2349+
an empty array.
23582350
</t>
23592351
</section>
23602352

2361-
<section title="additionalItems" anchor="additionalItems">
2353+
<section title="items" anchor="items">
23622354
<t>
2363-
The value of "additionalItems" MUST be a valid JSON Schema.
2355+
The value of "items" MUST be a valid JSON Schema.
23642356
</t>
23652357
<t>
2366-
The behavior of this keyword depends on the presence and
2367-
annotation result of "items" within the same schema object.
2368-
If "items" is present, and its annotation result is a number,
2369-
validation succeeds if every instance element at an index
2370-
greater than that number validates against "additionalItems".
2371-
</t>
2372-
<t>
2373-
Otherwise, if "items" is absent or its annotation result
2374-
is the boolean true, "additionalItems" MUST be ignored.
2358+
This keyword applies its subschema to all instance elements
2359+
at indexes greater than the length of the "prefixItems" array
2360+
in the same schema object, as reported by the annotation result
2361+
of that "prefixItems" keyword. If no such annotation
2362+
result exists, "items" applies its subschema to all instance
2363+
array elements.
2364+
<cref>
2365+
Note that the behavior of "items" without "prefixItems" is
2366+
identical to that of the schema form of "items" in prior drafts.
2367+
When "prefixItems" is present, the behavior of "items" is
2368+
identical to the former "additionalItems" keyword.
2369+
</cref>
23752370
</t>
23762371
<t>
2377-
If the "additionalItems" subschema is applied to any
2372+
If the "items" subschema is applied to any
23782373
positions within the instance array, it produces an
2379-
annotation result of boolean true, analogous to the
2380-
single schema behavior of "items". If any "additionalItems"
2381-
keyword from any subschema applied to the same instance
2382-
location produces an annotation value of true, then
2383-
the combined result from these keywords is also true.
2374+
annotation result of boolean true, indicating that all remaining array
2375+
elements have been evaluated against this keyword's subschema.
23842376
</t>
23852377
<t>
23862378
Omitting this keyword has the same assertion behavior as
@@ -2389,7 +2381,7 @@
23892381
<t>
23902382
Implementations MAY choose to implement or optimize this keyword
23912383
in another way that produces the same effect, such as by directly
2392-
checking for the presence and size of an "items" array.
2384+
checking for the presence and size of a "prefixItems" array.
23932385
Implementations that do not support annotation collection MUST do so.
23942386
</t>
23952387
</section>
@@ -2401,7 +2393,7 @@
24012393
<t>
24022394
The behavior of this keyword depends on the annotation results of
24032395
adjacent keywords that apply to the instance location being validated.
2404-
Specifically, the annotations from "items" and "additionalItems",
2396+
Specifically, the annotations from "prefixItems", "items", and "contains",
24052397
which can come from those keywords when they are adjacent to the
24062398
"unevaluatedItems" keyword. Those two annotations, as well as
24072399
"unevaluatedItems", can also result from any and all adjacent
@@ -2410,33 +2402,25 @@
24102402
defined in this document.
24112403
</t>
24122404
<t>
2413-
If an "items" annotation is present, and its annotation result
2414-
is a number, and no "additionalItems" or "unevaluatedItems"
2415-
annotation is present, then validation succeeds if every instance
2416-
element at an index greater than the "items" annotation validates
2417-
against "unevaluatedItems".
2405+
If no relevant annotations are present, the "unevaluatedItems"
2406+
subschema MUST be applied to all locations in the array.
2407+
If a boolean true value is present from any of the relevant annotations,
2408+
"unevaluatedItems" MUST be ignored. Otherwise, the subschema
2409+
MUST be applied to any index greater than the largest annotation
2410+
value for "prefixItems", which does not appear in any annotation
2411+
value for "contains".
24182412
</t>
24192413
<t>
2420-
Otherwise, if any "items", "additionalItems", or "unevaluatedItems"
2421-
annotations are present with a value of boolean true, then
2422-
"unevaluatedItems" MUST be ignored. However, if none of these
2423-
annotations are present, "unevaluatedItems" MUST be applied to
2424-
all locations in the array.
2425-
</t>
2426-
<t>
2427-
This means that "items", "additionalItems", and all in-place applicators
2428-
MUST be evaluated before this keyword can be evaluated. Authors of
2429-
extension keywords MUST NOT define an in-place applicator that would need
2430-
to be evaluated before this keyword.
2414+
This means that "prefixItems", "items", "contains", and all in-place
2415+
applicators MUST be evaluated before this keyword can be evaluated.
2416+
Authors of extension keywords MUST NOT define an in-place applicator
2417+
that would need to be evaluated before this keyword.
24312418
</t>
24322419
<t>
24332420
If the "unevaluatedItems" subschema is applied to any
24342421
positions within the instance array, it produces an
24352422
annotation result of boolean true, analogous to the
2436-
single schema behavior of "items". If any "unevaluatedItems"
2437-
keyword from any subschema applied to the same instance
2438-
location produces an annotation value of true, then
2439-
the combined result from these keywords is also true.
2423+
behavior of "items".
24402424
</t>
24412425
<t>
24422426
Omitting this keyword has the same assertion behavior as
@@ -2459,6 +2443,12 @@
24592443
array element even after the first match has been found. This
24602444
is to ensure that all possible annotations are collected.
24612445
</t>
2446+
<t>
2447+
This keyword produces an annotation value which is an array of
2448+
the indexes to which this keyword validates successfully when applying
2449+
its subschema, in ascending order. The value MAY be a boolean true if the
2450+
subschema validated successfully when applied to every index of the instance.
2451+
</t>
24622452
</section>
24632453
</section>
24642454

@@ -3800,9 +3790,9 @@ https://example.com/schemas/common#/$defs/count/minimum
38003790
<t hangText="draft-handrews-json-schema-03">
38013791
<list style="symbols">
38023792
<t></t>
3803-
<t></t>
3804-
<t></t>
3805-
<t></t>
3793+
<t>Array-value "items" functionality is now "prefixItems"</t>
3794+
<t>"items" subsumes the old function of "additionalItems"</t>
3795+
<t>"contains" and "unevaluatedItems" interactions now specified</t>
38063796
<t></t>
38073797
<t></t>
38083798
<t></t>

meta/applicator.json

+2-7
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@
88

99
"title": "Applicator vocabulary meta-schema",
1010
"properties": {
11-
"additionalItems": { "$recursiveRef": "#" },
11+
"prefixItems": { "$ref": "#/$defs/schemaArray" },
12+
"items": { "$recursiveRef": "#" },
1213
"unevaluatedItems": { "$recursiveRef": "#" },
13-
"items": {
14-
"anyOf": [
15-
{ "$recursiveRef": "#" },
16-
{ "$ref": "#/$defs/schemaArray" }
17-
]
18-
},
1914
"contains": { "$recursiveRef": "#" },
2015
"additionalProperties": { "$recursiveRef": "#" },
2116
"unevaluatedProperties": { "$recursiveRef": "#" },

0 commit comments

Comments
 (0)