@@ -185,6 +185,98 @@ Here's how you would covert a schema using `$recursiveRef` to use `$dynamicRef`.
185
185
</tr >
186
186
</table >
187
187
188
+ ## contains and unevaluatedItems
189
+ In the previous draft, it wasn't specified how or if the ` contains ` keyword
190
+ affects the ` unevaluatedItems ` keyword. This draft specifies that any item in an
191
+ array that passes validation of the ` contains ` schema is considered "evaluated".
192
+
193
+ This allows you to use ` contains ` to express some constraints more cleanly than
194
+ you could in previous drafts. This example show how you can express an array
195
+ that has some item matching one schema and everything else matching another
196
+ schema.
197
+
198
+ <table >
199
+ <tr >
200
+ <th>Draft 2019-09</th>
201
+ <th>Draft 2020-12</th>
202
+ </tr >
203
+ <tr >
204
+ <td><pre>{
205
+ "type": "array",
206
+ "contains": { "type": "string" },
207
+ "items": {
208
+ "anyOf": [
209
+ { "type": "string" },
210
+ { "type": "number" }
211
+ ]
212
+ }
213
+ }</pre ></td >
214
+ <td ><pre >{
215
+ "type": "array",
216
+ "contains": { "type": "string" },
217
+ "unevaluatedItems": { "type": "number" }
218
+ }
219
+
220
+
221
+
222
+
223
+
224
+ </pre ></td >
225
+ </tr >
226
+ </table >
227
+
228
+ Unfortunately, this change means you may not be able to use ` contains ` in some
229
+ situations you did before. Consider this draft 2019-09 schema describing a tuple
230
+ of two strings where one of the two must be three or more characters long and
231
+ any additional items are not allowed.
232
+
233
+ ``` json
234
+ {
235
+ "$schema" : " https://json-schema.org/draft/2019-09/schema" ,
236
+ "type" : " array" ,
237
+ "items" : [{ "type" : " string" }, { "type" : " string" }],
238
+ "contains" : { "type" : " string" , "minLength" : 3 },
239
+ "unevaluatedItems" : false
240
+ }
241
+ ```
242
+
243
+ Given this schema, the instance ` ["a", "b", "ccc"] ` will fail because ` "ccc" ` is
244
+ considered unevaluated and fails the ` unevaluatedItems ` keyword. Now let's
245
+ naively convert that example to a draft 2020-12 schema.
246
+
247
+ ``` json
248
+ {
249
+ "$schema" : " https://json-schema.org/draft/2020-12/schema" ,
250
+ "type" : " array" ,
251
+ "prefixItems" : [{ "type" : " string" }, { "type" : " string" }],
252
+ "contains" : { "type" : " string" , "minLength" : 3 },
253
+ "unevaluatedItems" : false
254
+ }
255
+ ```
256
+
257
+ Given this schema, the instance ` ["a", "b", "ccc"] ` will pass because ` "ccc" ` is
258
+ considered evaluated and doesn't not apply to the ` unevaluatedItems ` keyword. To
259
+ fix this problem we can use the same boolean algebra transformation we used to
260
+ use before we had the ` contains ` keyword.
261
+
262
+ ``` json
263
+ {
264
+ "$schema" : " https://json-schema.org/draft/2020-12/schema" ,
265
+ "type" : " array" ,
266
+ "prefixItems" : [{ "type" : " string" }, { "type" : " string" }],
267
+ "not" : {
268
+ "items" : {
269
+ "not" : { "type" : " string" , "minLength" : 3 }
270
+ }
271
+ },
272
+ "unevaluatedItems" : false
273
+ }
274
+ ```
275
+
276
+ Given this schema, the instance ` ["a", "b", "ccc"] ` will fail because ` "ccc" ` is
277
+ considered unevaluated and fails the ` unevaluatedItems ` keyword like it did in
278
+ previous drafts.
279
+
188
280
## Vocabulary Changes
189
281
The ` unevaluatedProperties ` and ` unevaluatedItems ` keywords have been moved from
190
282
the applicator vocabulary to their own vocabulary designated which is required
0 commit comments