You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
``` setSerialization(bool $serialization) ``` <br><br>Example:<br> ``` setSerialization(true) ``` | If set to true the serialization methods `toArray` and `toJSON` will be added to the public interface of the generated classes. | false
91
91
``` setOutputEnabled(bool $outputEnabled) ``` <br><br>Example:<br> ``` setOutputEnabled(false) ``` | Enable or disable output of the generation process to STDOUT | true
92
92
``` setErrorRegistryClass(string $exceptionClass) ``` <br><br>Example:<br> ``` setErrorRegistryClass(CustomException::class) ``` | Define a custom exception implementing the ErrorRegistryExceptionInterface to be used. The exception will be thrown if a validation fails and error collection is **enabled** | ErrorRegistryException::class
93
-
``` setExceptionClass(string $exceptionClass) ``` <br><br>Example:<br> ``` setExceptionClass(CustomException::class) ``` | Define a custom exception to be used. The exception will be thrown if a validation fails and error collection is **disabled** | ValidationException::class
94
93
``` addFilter(FilterInterface $filter) ``` <br><br>Example:<br> ``` addFilter(new CustomFilter()) ``` | Add a custom filter to the generator. Check out the docs for more details. | -
Copy file name to clipboardExpand all lines: docs/source/combinedSchemas/allOf.rst
+15-2Lines changed: 15 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -34,12 +34,12 @@ Generated interface:
34
34
public function getExample(): float;
35
35
36
36
37
-
Possible exception (if a string is provided):
37
+
Possible exception (eg. if a string is provided):
38
38
39
39
.. code-block:: none
40
40
41
41
Invalid value for example declined by composition constraint.
42
-
Requires to match 2 composition elements but matched 0 elements.
42
+
Requires to match all composition elements but matched 0 elements.
43
43
- Composition element #1: Failed
44
44
* Invalid type for example. Requires float, got string
45
45
- Composition element #2: Failed
@@ -55,6 +55,19 @@ Possible exception (if eg. 5 is provided, which matches only one subschema):
55
55
- Composition element #2: Failed
56
56
* Value for example must be a multiple of 3
57
57
58
+
The thrown exception will be a *PHPModelGenerator\\Exception\\ComposedValue\\AllOfException* which provides the following methods to get further error details:
59
+
60
+
.. code-block:: php
61
+
62
+
// returns a two-dimensional array which contains all validation exceptions grouped by composition elements
63
+
public function getCompositionErrorCollection(): array
64
+
// get the amount of succeeded composition elements
65
+
public function getSucceededCompositionElements(): int
66
+
// get the name of the property which failed
67
+
public function getPropertyName(): string
68
+
// get the value provided to the property
69
+
public function getProvidedValue()
70
+
58
71
.. hint::
59
72
60
73
When combining multiple nested objects with an `allOf` composition a `merged property <mergedProperty.html>`__ will be generated
Copy file name to clipboardExpand all lines: docs/source/combinedSchemas/anyOf.rst
+13Lines changed: 13 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -45,6 +45,19 @@ Possible exception (if a string is provided):
45
45
- Composition element #2: Failed
46
46
* Invalid type for example. Requires float, got string
47
47
48
+
The thrown exception will be a *PHPModelGenerator\\Exception\\ComposedValue\\AnyOfException* which provides the following methods to get further error details:
49
+
50
+
.. code-block:: php
51
+
52
+
// returns a two-dimensional array which contains all validation exceptions grouped by composition elements
53
+
public function getCompositionErrorCollection(): array
54
+
// get the amount of succeeded composition elements
55
+
public function getSucceededCompositionElements(): int
56
+
// get the name of the property which failed
57
+
public function getPropertyName(): string
58
+
// get the value provided to the property
59
+
public function getProvidedValue()
60
+
48
61
.. hint::
49
62
50
63
When combining multiple nested objects with an `anyOf` composition a `merged property <mergedProperty.html>`__ will be generated
Copy file name to clipboardExpand all lines: docs/source/combinedSchemas/not.rst
+13Lines changed: 13 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -32,3 +32,16 @@ Possible exceptions:
32
32
Invalid value for property declined by composition constraint.
33
33
Requires to match none composition element but matched 1 elements.
34
34
- Composition element #1: Valid
35
+
36
+
The thrown exception will be a *PHPModelGenerator\\Exception\\ComposedValue\\NotException* which provides the following methods to get further error details:
37
+
38
+
.. code-block:: php
39
+
40
+
// returns a two-dimensional array which contains all validation exceptions grouped by composition elements
41
+
public function getCompositionErrorCollection(): array
42
+
// get the amount of succeeded composition elements
43
+
public function getSucceededCompositionElements(): int
Copy file name to clipboardExpand all lines: docs/source/combinedSchemas/oneOf.rst
+13Lines changed: 13 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -55,6 +55,19 @@ Possible exception (if eg. 15 is provided, which matches both subschemas):
55
55
- Composition element #1: Valid
56
56
- Composition element #2: Valid
57
57
58
+
The thrown exception will be a *PHPModelGenerator\\Exception\\ComposedValue\\OneOfException* which provides the following methods to get further error details:
59
+
60
+
.. code-block:: php
61
+
62
+
// returns a two-dimensional array which contains all validation exceptions grouped by composition elements
63
+
public function getCompositionErrorCollection(): array
64
+
// get the amount of succeeded composition elements
65
+
public function getSucceededCompositionElements(): int
66
+
// get the name of the property which failed
67
+
public function getPropertyName(): string
68
+
// get the value provided to the property
69
+
public function getProvidedValue()
70
+
58
71
.. hint::
59
72
60
73
When combining multiple nested objects with an `oneOf` composition a `merged property <mergedProperty.html>`__ will be generated
Copy file name to clipboardExpand all lines: docs/source/complexTypes/array.rst
+89-1Lines changed: 89 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,17 @@ Possible exceptions:
31
31
32
32
* Invalid type for example. Requires array, got __TYPE__
33
33
34
+
The thrown exception will be a *PHPModelGenerator\\Exception\\Generic\\InvalidTypeException* which provides the following methods to get further error details:
35
+
36
+
.. code-block:: php
37
+
38
+
// returns a string if the property expects exactly one type, an array if the property accepts multiple types
39
+
public function getExpectedType()
40
+
// get the name of the property which failed
41
+
public function getPropertyName(): string
42
+
// get the value provided to the property
43
+
public function getProvidedValue()
44
+
34
45
Items
35
46
^^^^^
36
47
@@ -56,10 +67,21 @@ With a schema like this all items must contain a string with at least two charac
56
67
57
68
.. code-block:: none
58
69
59
-
Invalid item in array example:
70
+
Invalid items in array example:
60
71
- invalid item #3
61
72
* Invalid type for item of array example. Requires string, got double
62
73
74
+
The thrown exception will be a *PHPModelGenerator\\Exception\\Arrays\\InvalidItemException* which provides the following methods to get further error details:
75
+
76
+
.. code-block:: php
77
+
78
+
// returns a two-dimensional array which contains all validation exceptions grouped by item index
79
+
public function getInvalidItems(): array
80
+
// get the name of the property which failed
81
+
public function getPropertyName(): string
82
+
// get the value provided to the property
83
+
public function getProvidedValue()
84
+
63
85
A more complex array may contain a nested object.
64
86
65
87
.. code-block:: json
@@ -160,6 +182,17 @@ If invalid tuples are provided a detailed exception will be thrown containing al
160
182
- invalid tuple #1
161
183
* Invalid type for name. Requires string, got boolean
162
184
185
+
The thrown exception will be a *PHPModelGenerator\\Exception\\Arrays\\InvalidTupleException* which provides the following methods to get further error details:
186
+
187
+
.. code-block:: php
188
+
189
+
// returns a two-dimensional array which contains all validation exceptions grouped by item index
190
+
public function getInvalidTuples()
191
+
// get the name of the property which failed
192
+
public function getPropertyName(): string
193
+
// get the value provided to the property
194
+
public function getProvidedValue()
195
+
163
196
.. hint::
164
197
165
198
Incomplete tuples are valid. Consequently an empty array provided for the schema shown above would pass the validation. Keep this in mind when designing tuple constraints. To force the given data to provide all tuples use tuple items combined with the `minItems` array size validation.
@@ -202,6 +235,19 @@ Possible exceptions:
202
235
203
236
* Tuple array example contains not allowed additional items. Expected 2 items, got 3
204
237
238
+
The thrown exception will be a *PHPModelGenerator\\Exception\\Arrays\\AdditionalTupleItemsException* which provides the following methods to get further error details:
239
+
240
+
.. code-block:: php
241
+
242
+
// Get the expected tuple amount
243
+
public function getExpectedAmount(): int
244
+
// Get the amount of items provided
245
+
public function getAmount(): int
246
+
// get the name of the property which failed
247
+
public function getPropertyName(): string
248
+
// get the value provided to the property
249
+
public function getProvidedValue()
250
+
205
251
If invalid additional items are provided a detailed exception will be thrown containing all violations:
206
252
207
253
.. code-block:: none
@@ -212,6 +258,17 @@ If invalid additional items are provided a detailed exception will be thrown con
212
258
- invalid additional item '5'
213
259
* Invalid type for additional item. Requires object, got int
214
260
261
+
The thrown exception will be a *PHPModelGenerator\\Exception\\Arrays\\InvalidAdditionalTupleItemsException* which provides the following methods to get further error details:
262
+
263
+
.. code-block:: php
264
+
265
+
// returns a two-dimensional array which contains all validation exceptions grouped by item index
266
+
public function getNestedExceptions(): array
267
+
// get the name of the property which failed
268
+
public function getPropertyName(): string
269
+
// get the value provided to the property
270
+
public function getProvidedValue()
271
+
215
272
Contains
216
273
--------
217
274
@@ -236,6 +293,15 @@ Possible exceptions:
236
293
237
294
* No item in array example matches contains constraint
238
295
296
+
The thrown exception will be a *PHPModelGenerator\\Exception\\Arrays\\ContainsException* which provides the following methods to get further error details:
297
+
298
+
.. code-block:: php
299
+
300
+
// get the name of the property which failed
301
+
public function getPropertyName(): string
302
+
// get the value provided to the property
303
+
public function getProvidedValue()
304
+
239
305
Size validation
240
306
---------------
241
307
@@ -260,6 +326,19 @@ Possible exceptions:
260
326
* Array example must not contain less than 2 items
261
327
* Array example must not contain more than 5 items
262
328
329
+
The thrown exception will be a *PHPModelGenerator\\Exception\\Arrays\\MaxItemsException* or a *PHPModelGenerator\\Exception\\Arrays\\MinItemsException* which provides the following methods to get further error details:
330
+
331
+
.. code-block:: php
332
+
333
+
// for a MaxItemsException: get the maximum amount of allowed items
334
+
public function getMaxItems(): int
335
+
// for a MinItemsException: get the minimum amount of required items
336
+
public function getMinItems(): int
337
+
// get the name of the property which failed
338
+
public function getPropertyName(): string
339
+
// get the value provided to the property
340
+
public function getProvidedValue()
341
+
263
342
Uniqueness
264
343
----------
265
344
@@ -281,3 +360,12 @@ The items of an array can be forced to be unique with the `uniqueItems` keyword.
281
360
Possible exceptions:
282
361
283
362
* Items of array example are not unique
363
+
364
+
The thrown exception will be an *PHPModelGenerator\\Exception\\Arrays\\UniqueItemsException* which provides the following methods to get further error details:
Copy file name to clipboardExpand all lines: docs/source/complexTypes/enum.rst
+11Lines changed: 11 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -55,3 +55,14 @@ Generated interface (no typehints are generated as it's an untyped enum):
55
55
Possible exceptions:
56
56
57
57
* Invalid value for example declined by enum constraint
58
+
59
+
The thrown exception will be an *PHPModelGenerator\\Exception\\Generic\\EnumException* which provides the following methods to get further error details:
Copy file name to clipboardExpand all lines: docs/source/complexTypes/multiType.rst
+12-1Lines changed: 12 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -26,6 +26,17 @@ Possible exceptions:
26
26
27
27
* Invalid type for property. Requires [float, string], got __TYPE__
28
28
29
+
The thrown exception will be a *PHPModelGenerator\\Exception\\Generic\\InvalidTypeException* which provides the following methods to get further error details:
30
+
31
+
.. code-block:: php
32
+
33
+
// returns a string if the property expects exactly one type, an array if the property accepts multiple types
34
+
public function getExpectedType()
35
+
// get the name of the property which failed
36
+
public function getPropertyName(): string
37
+
// get the value provided to the property
38
+
public function getProvidedValue()
39
+
29
40
Additional validators
30
41
---------------------
31
42
@@ -54,6 +65,6 @@ For example if an array **["Hello", 123, "Goodbye"]** is given the validation wi
54
65
55
66
.. code-block:: none
56
67
57
-
Invalid item in array example:
68
+
Invalid items in array example:
58
69
- invalid item #1
59
70
* Invalid type for item of array example. Requires string, got integer
0 commit comments