Skip to content

Commit da05d90

Browse files
committed
Release Notes: tuple items changes
1 parent bd73d0a commit da05d90

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

draft/2020-12/release-notes.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,103 @@
22
title: JSON Schema 2020-12 Release Notes
33
layout: page
44
---
5+
## Changes to items and additionalItems
6+
The keywords used for defining arrays and tuples have been redesigned to help
7+
lower the learning curve for JSON Schema. Since the `items` keyword was used for
8+
both types, we would often see people mistakenly defining a tuple when they
9+
meant to define an array and not understand why only the first item in the array
10+
was validating.
11+
12+
The `items` and `additionalItems` keywords have been replaced with `prefixItems`
13+
and `items` where `prefixItems` has the same functionality as the
14+
array-of-schemas for of the old `items` and the new `items` keyword has the same
15+
functionality as the old `additionalItems` keyword.
16+
17+
Although the meaning of `items` has changed, the syntax for defining arrays
18+
remains the same. Only the syntax for defining tuples has changed. The idea is
19+
that an array has items (`items`) and optionally has some positionally defined
20+
items that come before the normal items (`prefixItems`).
21+
22+
Here are some examples to illustrate the changes.
23+
24+
### Open tuple
25+
<table>
26+
<tr>
27+
<th>Draft 2019-09</th>
28+
<th>Draft 2020-12</th>
29+
</tr>
30+
<tr>
31+
<td>
32+
<pre>{
33+
"items": [
34+
{ "$ref": "#/$defs/foo" },
35+
{ "$ref": "#/$defs/bar" }
36+
]
37+
}</pre>
38+
</td>
39+
<td>
40+
<pre>{
41+
"prefixItems": [
42+
{ "$ref": "#/$defs/foo" },
43+
{ "$ref": "#/$defs/bar" }
44+
]
45+
}</pre>
46+
</td>
47+
</tr>
48+
</table>
49+
50+
### Closed tuple
51+
<table>
52+
<tr>
53+
<th>Draft 2019-09</th>
54+
<th>Draft 2020-12</th>
55+
</tr>
56+
<tr>
57+
<td>
58+
<pre>{
59+
"items": [
60+
{ "$ref": "#/$defs/foo" },
61+
{ "$ref": "#/$defs/bar" }
62+
],
63+
"additionalItems": false
64+
}</pre>
65+
</td>
66+
<td>
67+
<pre>{
68+
"prefixItems": [
69+
{ "$ref": "#/$defs/foo" },
70+
{ "$ref": "#/$defs/bar" }
71+
],
72+
"items": false
73+
}</pre>
74+
</td>
75+
</tr>
76+
</table>
77+
78+
### Tuple with constrained additional items
79+
<table>
80+
<tr>
81+
<th>Draft 2019-09</th>
82+
<th>Draft 2020-12</th>
83+
</tr>
84+
<tr>
85+
<td>
86+
<pre>{
87+
"items": [
88+
{ "$ref": "#/$defs/foo" },
89+
{ "$ref": "#/$defs/bar" }
90+
],
91+
"additionalItems": { "$ref": "#/$defs/baz" }
92+
}</pre>
93+
</td>
94+
<td>
95+
<pre>{
96+
"prefixItems": [
97+
{ "$ref": "#/$defs/foo" },
98+
{ "$ref": "#/$defs/bar" }
99+
],
100+
"items": { "$ref": "#/$defs/baz" }
101+
}</pre>
102+
</td>
103+
</tr>
104+
</table>

0 commit comments

Comments
 (0)