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
Passthrough a value through the ObjectInstantiationDecorator instrad of adding a validation error to keep validation order.
Instead of throwing an invalid type, requires object got object error in case of an invalid class execute an instanceof validation.
Add nested object schema test cases
Schema Dependency documentation
Copy file name to clipboardExpand all lines: docs/source/complexTypes/object.rst
+58-1Lines changed: 58 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -343,7 +343,64 @@ As stated above the dependency declaration is not bidirectional. If the presence
343
343
Schema Dependencies
344
344
^^^^^^^^^^^^^^^^^^^
345
345
346
-
Schema dependencies are currently not supported.
346
+
Schema dependencies allow you to define a schema which must be fulfilled if a given property is present. The schema provided for the property must be either an object schema, a composition schema or a reference to an object schema.
347
+
348
+
.. code-block:: json
349
+
350
+
{
351
+
"type": "object",
352
+
"$id": "CreditCardOwner"
353
+
"properties": {
354
+
"credit_card": {
355
+
"type": "integer"
356
+
}
357
+
},
358
+
"dependencies": {
359
+
"credit_card": {
360
+
"properties": {
361
+
"billing_address": {
362
+
"type": "string"
363
+
},
364
+
"date_of_birth": {
365
+
"type": "string"
366
+
}
367
+
},
368
+
"required": [
369
+
"date_of_birth"
370
+
]
371
+
}
372
+
}
373
+
}
374
+
375
+
The properties of the dependant schema will be transferred to the base model during the model generation process. If the property which defines the dependency isn't present they will not be required by the base model.
376
+
377
+
Generated interface:
378
+
379
+
.. code-block:: php
380
+
381
+
// class CreditCardOwner
382
+
// base properties
383
+
public function setCreditCard(?int $creditCard): self;
384
+
public function getCreditCard(): ?int;
385
+
386
+
// inherited properties
387
+
public function setBillingAddress($billingAddress): self;
388
+
public function getBillingAddress();
389
+
public function setDateOfBirth($dateOfBirth): self;
390
+
public function getDateOfBirth();
391
+
392
+
.. hint::
393
+
394
+
Basically this means your base object gets getters and setters for the additional properties transferred from the schema dependency but this getters and setters won't perform any validation. If you require type checks and validations performed on the properties define them in your main schema as not required properties and require them as a property dependency.
395
+
396
+
Possible exceptions:
397
+
398
+
.. code-block:: none
399
+
400
+
Invalid schema which is dependant on credit_card:
401
+
- Missing required value for date_of_birth
402
+
403
+
Multiple violations against the schema dependency may be included.
0 commit comments