Skip to content

Commit 019aac5

Browse files
committed
Add tuple documentation
1 parent 7638922 commit 019aac5

File tree

2 files changed

+93
-1
lines changed

2 files changed

+93
-1
lines changed

docs/source/complexTypes/array.rst

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,98 @@ The *getMembers* function of the class *Family* is typehinted with *@returns Mem
115115
Tuples
116116
------
117117

118-
TODO: documentation
118+
A tuple array defines the structure of each array item on it's own. A tuple array is defined by providing an array of schemas with the `items` keyword.
119+
120+
Items
121+
^^^^^
122+
123+
.. code-block:: json
124+
125+
{
126+
"id": "example",
127+
"type": "object",
128+
"properties": {
129+
"example": {
130+
"type": "array",
131+
"items": [
132+
{
133+
"type": "string",
134+
"minLength": 2
135+
},
136+
{
137+
"type": "object",
138+
"properties": {
139+
"name": {
140+
"type": "string"
141+
}
142+
}
143+
}
144+
]
145+
}
146+
}
147+
}
148+
149+
Possible exceptions:
150+
151+
* Missing tuple item in array example. Requires 2 items, got 1
152+
153+
If invalid tuples are provided a detailed exception will be thrown containing all violations:
154+
155+
.. code-block:: none
156+
157+
Invalid tuple item in array example:
158+
- invalid tuple #1
159+
* Invalid type for tuple item #1 of array example. Requires string, got int
160+
- invalid tuple #1
161+
* Invalid type for name. Requires string, got boolean
162+
163+
Additional items
164+
^^^^^^^^^^^^^^^^
165+
166+
Using the keyword `additionalItems` the array can be limited to not contain any other value by providing `false`. If a schema is provided all additional items must be valid against the provided schema. Simple checks like 'must contain a string' are possible as well as checks like 'must contain an object with a specific structure'.
167+
168+
.. code-block:: json
169+
170+
{
171+
"id": "example",
172+
"type": "object",
173+
"properties": {
174+
"example": {
175+
"type": "array",
176+
"items": [
177+
{
178+
"type": "string",
179+
"minLength": 2
180+
},
181+
{
182+
"type": "integer"
183+
},
184+
],
185+
"additionalItems": {
186+
"type": "object",
187+
"properties": {
188+
"name": {
189+
"type": "string"
190+
}
191+
}
192+
}
193+
}
194+
}
195+
}
196+
197+
Possible exceptions:
198+
199+
* Tuple array example contains not allowed additional items. Expected 2 items, got 3
200+
201+
If invalid additional items are provided a detailed exception will be thrown containing all violations:
202+
203+
.. code-block:: none
204+
205+
Tuple array property contains invalid additional items.
206+
- invalid additional item '3'
207+
* Invalid type for name. Requires string, got integer
208+
- invalid additional item '5'
209+
* Invalid type for additional item. Requires object, got int
119210
120211
Contains
121212
--------

src/PropertyProcessor/Property/ArrayProcessor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ private function addItemsValidation(PropertyInterface $property, array $property
128128
return;
129129
}
130130

131+
// TODO: more detailed exception including the violations
131132
$this->addItemValidator(
132133
$property,
133134
$propertyData[self::JSON_FIELD_ITEMS],

0 commit comments

Comments
 (0)