Skip to content

Commit 93dfd6e

Browse files
committed
"items"/"contains"/"unevaluatedItems"/"+prefixItems/-additionalItems"
This reworks the array applicators in several ways: * "prefixItems" takes on the former role of the array form of "items" * "items" keeps its single-schema role, and takes on the role of "additionalItems" when "prefixItems" is present * "contains" now produces an annotation indicating what it evaluated * "unevaluatedItems" now respects "contains", and the language around interpreting the relevant annotation is (hopefully) less convoluted Note that this does not address the change to put unevaluatedItems into a separate vocabulary with unevaluatedProperties, which will be done as a separate PR.
1 parent 5ebe3ca commit 93dfd6e

File tree

2 files changed

+49
-68
lines changed

2 files changed

+49
-68
lines changed

jsonschema-core.xml

Lines changed: 47 additions & 61 deletions
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,49 @@
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.
23422336
</t>
23432337
<t>
23442338
This keyword produces an annotation value which is the largest
23452339
index to which this keyword applied a subschema. The value
23462340
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.
2341+
index of the instance, such as is produced by the "items" keyword.
23542342
</t>
23552343
<t>
23562344
Omitting this keyword has the same assertion behavior as
2357-
an empty schema.
2345+
an empty array.
23582346
</t>
23592347
</section>
23602348

2361-
<section title="additionalItems" anchor="additionalItems">
2362-
<t>
2363-
The value of "additionalItems" MUST be a valid JSON Schema.
2364-
</t>
2349+
<section title="items" anchor="items">
23652350
<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".
2351+
The value of "items" MUST be a valid JSON Schema.
23712352
</t>
23722353
<t>
2373-
Otherwise, if "items" is absent or its annotation result
2374-
is the boolean true, "additionalItems" MUST be ignored.
2354+
This keyword applies its subschema to all instance elements
2355+
at indexes greater than the length of the "prefixItems" array
2356+
in the same schema object, as reported by the annotation result
2357+
of that "prefixItems" keyword. If no such annotation
2358+
result exists, "items" applies its subschema to all instance
2359+
array elements.
2360+
<cref>
2361+
Note that the behavior of "items" without "prefixItems" is
2362+
identical to that of the schema form of "items" in prior drafts.
2363+
When "prefixItems" is present, the behavior of "items" is
2364+
identical to the former "additionalItems" keyword.
2365+
</cref>
23752366
</t>
23762367
<t>
2377-
If the "additionalItems" subschema is applied to any
2368+
If the "items" subschema is applied to any
23782369
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.
2370+
annotation result of boolean true, indicating that all remaining array
2371+
elements have been evaluated against this keyword's subschema.
23842372
</t>
23852373
<t>
23862374
Omitting this keyword has the same assertion behavior as
@@ -2389,7 +2377,7 @@
23892377
<t>
23902378
Implementations MAY choose to implement or optimize this keyword
23912379
in another way that produces the same effect, such as by directly
2392-
checking for the presence and size of an "items" array.
2380+
checking for the presence and size of a "prefixItems" array.
23932381
Implementations that do not support annotation collection MUST do so.
23942382
</t>
23952383
</section>
@@ -2401,7 +2389,7 @@
24012389
<t>
24022390
The behavior of this keyword depends on the annotation results of
24032391
adjacent keywords that apply to the instance location being validated.
2404-
Specifically, the annotations from "items" and "additionalItems",
2392+
Specifically, the annotations from "prefixItems", "items", and "contains",
24052393
which can come from those keywords when they are adjacent to the
24062394
"unevaluatedItems" keyword. Those two annotations, as well as
24072395
"unevaluatedItems", can also result from any and all adjacent
@@ -2410,33 +2398,25 @@
24102398
defined in this document.
24112399
</t>
24122400
<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".
2401+
If no relevant annotations are present, the "unevaluatedItems"
2402+
subschema MUST be applied to all locations in the array.
2403+
If a boolean true value is present from any of the relevant annotations,
2404+
"unevaluatedItems" MUST be ignored. Otherwise, the subschema
2405+
MUST be applied to any index greater than the largest annotation
2406+
value for "prefixItems", which does not appear in any annotation
2407+
value for "contains".
24182408
</t>
24192409
<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.
2410+
This means that "prefixItems", "items", "contains", and all in-place
2411+
applicators MUST be evaluated before this keyword can be evaluated.
2412+
Authors of extension keywords MUST NOT define an in-place applicator
2413+
that would need to be evaluated before this keyword.
24312414
</t>
24322415
<t>
24332416
If the "unevaluatedItems" subschema is applied to any
24342417
positions within the instance array, it produces an
24352418
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.
2419+
behavior of "items".
24402420
</t>
24412421
<t>
24422422
Omitting this keyword has the same assertion behavior as
@@ -2459,6 +2439,12 @@
24592439
array element even after the first match has been found. This
24602440
is to ensure that all possible annotations are collected.
24612441
</t>
2442+
<t>
2443+
This keyword produces an annotation value which is an array of
2444+
the indexes to which this keyword successfully applied its subschema,
2445+
in ascending order. The value MAY be a boolean true if the subschema
2446+
was successfully applied to every index of the instance.
2447+
</t>
24622448
</section>
24632449
</section>
24642450

meta/applicator.json

Lines changed: 2 additions & 7 deletions
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)