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

Fix #22: Explain about additionalItems as object. #80

Merged
merged 1 commit into from
Aug 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion source/reference/array.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Here's the example schema:
[1600, "Pennsylvania", "Avenue", "NW", "Washington"]

The ``additionalItems`` keyword controls whether it's valid to have
additional items in the array beyond what is defined in the schema.
additional items in the array beyond what is defined in ``items``.
Here, we'll reuse the example schema above, but set
``additionalItems`` to ``false``, which has the effect of disallowing
extra items in the array.
Expand Down Expand Up @@ -206,6 +206,43 @@ extra items in the array.
// extra items:
[1600, "Pennsylvania", "Avenue", "NW", "Washington"]

The ``additionalItems`` keyword may also be a schema to validate against every
additional item in the array. In that case, we could say that additional items
are allowed, as long as they are all strings:

.. schema_example::

{
"type": "array",
"items": [
{
"type": "number"
},
{
"type": "string"
},
{
"type": "string",
"enum": ["Street", "Avenue", "Boulevard"]
},
{
"type": "string",
"enum": ["NW", "NE", "SW", "SE"]
}
],
"additionalItems": { "type": "string" }
}
--
// Extra string items are ok...
[1600, "Pennsylvania", "Avenue", "NW", "Washington"]
--X
// ..but not anything else
[1600, "Pennsylvania", "Avenue", "NW", 20500]

.. note::

``additionalItems`` doesn't make sense if you're doing "list validation"
(``items`` is an object), and is ignored in the case.

.. index::
single: array; length
Expand Down