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
Copy file name to clipboardExpand all lines: docs/source/generic/default.rst
+122Lines changed: 122 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,3 +37,125 @@ Behaviour with different inputs:
37
37
If no value for a property with a default value is defined the default value will be validated against all rules defined in the schema. Consequently you may get a validation error if the default value doesn't match your constraints.
38
38
39
39
If you use a `filter <../nonStandardExtensions/filter.html>`__ on a property with a default value the default value will be filtered if no value is provided for the property. If the filter is a `transforming filter <../nonStandardExtensions/filter.html#transforming-filter>`__ the default value will be transformed.
40
+
41
+
Branch defaults in compositions
42
+
--------------------------------
43
+
44
+
Properties declared inside ``oneOf``, ``anyOf``, ``allOf``, ``if``/``then``/``else`` branches may
45
+
also carry a ``"default"`` value. The generator supports branch-level defaults and applies them
46
+
conditionally depending on the composition keyword.
47
+
48
+
**oneOf / anyOf / if–then–else**
49
+
50
+
For compositions where a single branch (or conditional branch) is active at a time, the branch
51
+
default is applied only when that branch is the active one. A user-supplied value always takes
52
+
precedence over the branch default.
53
+
54
+
.. code-block:: json
55
+
56
+
{
57
+
"$id": "example",
58
+
"type": "object",
59
+
"oneOf": [
60
+
{
61
+
"properties": {
62
+
"kind": {
63
+
"type": "string",
64
+
"enum": ["A"]
65
+
}
66
+
},
67
+
"required": ["kind"]
68
+
},
69
+
{
70
+
"properties": {
71
+
"kind": {
72
+
"type": "string",
73
+
"enum": ["B"]
74
+
},
75
+
"timeout": {
76
+
"type": "integer",
77
+
"default": 30
78
+
}
79
+
},
80
+
"required": ["kind"]
81
+
}
82
+
]
83
+
}
84
+
85
+
.. code-block:: php
86
+
87
+
// Branch B is active — timeout defaults to 30
88
+
$example = new Example(['kind' => 'B']);
89
+
$example->getTimeout(); // returns 30
90
+
91
+
// Branch A is active — timeout has no default; returns null
92
+
$example = new Example(['kind' => 'A']);
93
+
$example->getTimeout(); // returns null
94
+
95
+
// User-supplied value overrides the branch default
96
+
$example = new Example(['kind' => 'B', 'timeout' => 60]);
97
+
$example->getTimeout(); // returns 60
98
+
99
+
Branch defaults are **not** included in ``getRawModelDataInput()``. Only values explicitly
0 commit comments