Skip to content

Commit 293705a

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 8f53864 commit 293705a

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": {
@@ -2141,11 +2141,11 @@
21412141
"additionalProperties" and itself
21422142
</t>
21432143
<t>
2144-
"additionalItems", whose behavior is defined in terms of "items"
2144+
"items", whose behavior is defined in terms of "prefixItems"
21452145
</t>
21462146
<t>
21472147
"unevaluatedItems", whose behavior is defined in terms of annotations
2148-
from "items", "additionalItems" and itself
2148+
from "prefixItems", "items", "contains", and itself
21492149
</t>
21502150
</list>
21512151
</t>
@@ -2324,61 +2324,49 @@
23242324
properties and array items, and combining their results.
23252325
</t>
23262326
<section title="Keywords for Applying Subschemas to Arrays">
2327-
<section title="items">
2327+
<section title="prefixItems">
23282328
<t>
2329-
The value of "items" MUST be either a valid JSON Schema or
2330-
an array of valid JSON Schemas.
2329+
The value of "prefixItems" MUST be an array of valid JSON Schemas.
23312330
</t>
23322331
<t>
2333-
If "items" is a schema, validation succeeds if all elements
2334-
in the array successfully validate against that schema.
2335-
</t>
2336-
<t>
2337-
If "items" is an array of schemas, validation succeeds if
2338-
each element of the instance validates against the schema at the
2339-
same position, if any.
2332+
Validation succeeds if each element of the instance validates
2333+
against the schema at the same position, if any.
23402334
</t>
23412335
<t>
23422336
This keyword produces an annotation value which is the largest
23432337
index to which this keyword applied a subschema. The value
23442338
MAY be a boolean true if a subschema was applied to every
2345-
index of the instance, such as when "items" is a schema.
2346-
</t>
2347-
<t>
2348-
Annotation results for "items" keywords from multiple
2349-
schemas applied to the same instance location are combined
2350-
by setting the combined result to true if any of the values
2351-
are true, and otherwise retaining the largest numerical value.
2339+
index of the instance, such as is produced by the "items" keyword.
23522340
</t>
23532341
<t>
23542342
Omitting this keyword has the same assertion behavior as
2355-
an empty schema.
2343+
an empty array.
23562344
</t>
23572345
</section>
23582346

2359-
<section title="additionalItems" anchor="additionalItems">
2360-
<t>
2361-
The value of "additionalItems" MUST be a valid JSON Schema.
2362-
</t>
2347+
<section title="items" anchor="items">
23632348
<t>
2364-
The behavior of this keyword depends on the presence and
2365-
annotation result of "items" within the same schema object.
2366-
If "items" is present, and its annotation result is a number,
2367-
validation succeeds if every instance element at an index
2368-
greater than that number validates against "additionalItems".
2349+
The value of "items" MUST be a valid JSON Schema.
23692350
</t>
23702351
<t>
2371-
Otherwise, if "items" is absent or its annotation result
2372-
is the boolean true, "additionalItems" MUST be ignored.
2352+
This keyword applies its subschema to all instance elements
2353+
at indexes greater than the length of the "prefixItems" array
2354+
in the same schema object, as reported by the annotation result
2355+
of that "prefixItems" keyword. If no such annotation
2356+
result exists, "items" applies its subschema to all instance
2357+
array elements.
2358+
<cref>
2359+
Note that the behavior of "items" without "prefixItems" is
2360+
identical to that of the schema form of "items" in prior drafts.
2361+
When "prefixItems" is present, the behavior of "items" is
2362+
identical to the former "additionalItems" keyword.
2363+
</cref>
23732364
</t>
23742365
<t>
2375-
If the "additionalItems" subschema is applied to any
2366+
If the "items" subschema is applied to any
23762367
positions within the instance array, it produces an
2377-
annotation result of boolean true, analogous to the
2378-
single schema behavior of "items". If any "additionalItems"
2379-
keyword from any subschema applied to the same instance
2380-
location produces an annotation value of true, then
2381-
the combined result from these keywords is also true.
2368+
annotation result of boolean true, indicating that all remaining array
2369+
elements have been evaluated against this keyword's subschema.
23822370
</t>
23832371
<t>
23842372
Omitting this keyword has the same assertion behavior as
@@ -2387,7 +2375,7 @@
23872375
<t>
23882376
Implementations MAY choose to implement or optimize this keyword
23892377
in another way that produces the same effect, such as by directly
2390-
checking for the presence and size of an "items" array.
2378+
checking for the presence and size of a "prefixItems" array.
23912379
Implementations that do not support annotation collection MUST do so.
23922380
</t>
23932381
</section>
@@ -2399,7 +2387,7 @@
23992387
<t>
24002388
The behavior of this keyword depends on the annotation results of
24012389
adjacent keywords that apply to the instance location being validated.
2402-
Specifically, the annotations from "items" and "additionalItems",
2390+
Specifically, the annotations from "prefixItems", "items", and "contains",
24032391
which can come from those keywords when they are adjacent to the
24042392
"unevaluatedItems" keyword. Those two annotations, as well as
24052393
"unevaluatedItems", can also result from any and all adjacent
@@ -2408,33 +2396,25 @@
24082396
defined in this document.
24092397
</t>
24102398
<t>
2411-
If an "items" annotation is present, and its annotation result
2412-
is a number, and no "additionalItems" or "unevaluatedItems"
2413-
annotation is present, then validation succeeds if every instance
2414-
element at an index greater than the "items" annotation validates
2415-
against "unevaluatedItems".
2399+
If no relevant annotations are present, the "unevaluatedItems"
2400+
subschema MUST be applied to all locations in the array.
2401+
If a boolean true value is present from any of the relevant annotations,
2402+
"unevaluatedItems" MUST be ignored. Otherwise, the subschema
2403+
MUST be applied to any index greater than the largest annotation
2404+
value for "prefixItems", which does not appear in any annotation
2405+
value for "contains".
24162406
</t>
24172407
<t>
2418-
Otherwise, if any "items", "additionalItems", or "unevaluatedItems"
2419-
annotations are present with a value of boolean true, then
2420-
"unevaluatedItems" MUST be ignored. However, if none of these
2421-
annotations are present, "unevaluatedItems" MUST be applied to
2422-
all locations in the array.
2423-
</t>
2424-
<t>
2425-
This means that "items", "additionalItems", and all in-place applicators
2426-
MUST be evaluated before this keyword can be evaluated. Authors of
2427-
extension keywords MUST NOT define an in-place applicator that would need
2428-
to be evaluated before this keyword.
2408+
This means that "prefixItems", "items", "contains", and all in-place
2409+
applicators MUST be evaluated before this keyword can be evaluated.
2410+
Authors of extension keywords MUST NOT define an in-place applicator
2411+
that would need to be evaluated before this keyword.
24292412
</t>
24302413
<t>
24312414
If the "unevaluatedItems" subschema is applied to any
24322415
positions within the instance array, it produces an
24332416
annotation result of boolean true, analogous to the
2434-
single schema behavior of "items". If any "unevaluatedItems"
2435-
keyword from any subschema applied to the same instance
2436-
location produces an annotation value of true, then
2437-
the combined result from these keywords is also true.
2417+
behavior of "items".
24382418
</t>
24392419
<t>
24402420
Omitting this keyword has the same assertion behavior as
@@ -2457,6 +2437,12 @@
24572437
array element even after the first match has been found. This
24582438
is to ensure that all possible annotations are collected.
24592439
</t>
2440+
<t>
2441+
This keyword produces an annotation value which is an array of
2442+
the indexes to which this keyword successfully applied its subschema,
2443+
in ascending order. The value MAY be a boolean true if the subschema
2444+
was successfully applied to every index of the instance.
2445+
</t>
24602446
</section>
24612447
</section>
24622448

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)