Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit acabfc6

Browse files
authored
Merge pull request #80 from mdboom/additionalItems
Fixes #22: Explain about ``additionalItems`` as object.
2 parents 0edcf9f + ffe36a7 commit acabfc6

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

source/reference/array.rst

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Here's the example schema:
169169
[1600, "Pennsylvania", "Avenue", "NW", "Washington"]
170170

171171
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``.
173173
Here, we'll reuse the example schema above, but set
174174
``additionalItems`` to ``false``, which has the effect of disallowing
175175
extra items in the array.
@@ -206,6 +206,43 @@ extra items in the array.
206206
// extra items:
207207
[1600, "Pennsylvania", "Avenue", "NW", "Washington"]
208208

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.
209246

210247
.. index::
211248
single: array; length

0 commit comments

Comments
 (0)