@@ -169,7 +169,7 @@ Here's the example schema:
169
169
[1600, "Pennsylvania", "Avenue", "NW", "Washington"]
170
170
171
171
The ``additionalItems `` keyword controls whether it's valid to have
172
- additional items in the array beyond what is defined in the schema .
172
+ additional items in the array beyond what is defined in `` items `` .
173
173
Here, we'll reuse the example schema above, but set
174
174
``additionalItems `` to ``false ``, which has the effect of disallowing
175
175
extra items in the array.
@@ -206,6 +206,43 @@ extra items in the array.
206
206
// extra items:
207
207
[1600, "Pennsylvania", "Avenue", "NW", "Washington"]
208
208
209
+ The ``additionalItems `` keyword may also be a schema to validate against every
210
+ additional item in the array. In that case, we could say that additional items
211
+ are allowed, as long as they are all strings:
212
+
213
+ .. schema_example ::
214
+
215
+ {
216
+ "type": "array",
217
+ "items": [
218
+ {
219
+ "type": "number"
220
+ },
221
+ {
222
+ "type": "string"
223
+ },
224
+ {
225
+ "type": "string",
226
+ "enum": ["Street", "Avenue", "Boulevard"]
227
+ },
228
+ {
229
+ "type": "string",
230
+ "enum": ["NW", "NE", "SW", "SE"]
231
+ }
232
+ ],
233
+ "additionalItems": { "type": "string" }
234
+ }
235
+ --
236
+ // Extra string items are ok...
237
+ [1600, "Pennsylvania", "Avenue", "NW", "Washington"]
238
+ --X
239
+ // ..but not anything else
240
+ [1600, "Pennsylvania", "Avenue", "NW", 20500]
241
+
242
+ .. note ::
243
+
244
+ ``additionalItems `` doesn't make sense if you're doing "list validation"
245
+ (``items `` is an object), and is ignored in the case.
209
246
210
247
.. index ::
211
248
single: array; length
0 commit comments