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/nonStandardExtensions/filter.rst
+62Lines changed: 62 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,6 +46,31 @@ If a list is used filters may include additional option parameters. In this case
46
46
}
47
47
}
48
48
49
+
Array filter
50
+
------------
51
+
52
+
Filters may be applied to arrays. In this case the filter operates on the whole array.
53
+
54
+
.. code-block:: json
55
+
56
+
{
57
+
"type": "object",
58
+
"properties": {
59
+
"names": {
60
+
"type": "array",
61
+
"filter": "notEmpty",
62
+
"items": {
63
+
"type": "string",
64
+
"filter": "trim"
65
+
}
66
+
}
67
+
}
68
+
}
69
+
70
+
The array filter is executed before the items are processed. Consequently strings which aren't empty at the beginning but are empty after the trim filter is applied to each element won't be filtered out in the example given above.
71
+
72
+
It is not possible to use transforming filters on arrays.
73
+
49
74
Transforming filter
50
75
-------------------
51
76
@@ -112,6 +137,40 @@ If the filter trim is used for a property which doesn't require a string value a
112
137
113
138
* Filter trim is not compatible with property type __TYPE__ for property __PROPERTY_NAME__
114
139
140
+
notEmpty
141
+
^^^^^^^^
142
+
143
+
The dateTime filter is only valid for array properties.
144
+
145
+
.. code-block:: json
146
+
147
+
{
148
+
"$id": "family",
149
+
"type": "object",
150
+
"properties": {
151
+
"members": {
152
+
"type": "array",
153
+
"filter": "notEmpty"
154
+
}
155
+
}
156
+
}
157
+
158
+
Let's have a look how the generated model behaves:
159
+
160
+
.. code-block:: php
161
+
162
+
// valid, the name will be NULL as the name is not required
163
+
$family = new Person([]);
164
+
165
+
// A valid example
166
+
$family = new Family(['members' => [null, null]]]);
167
+
$family->getMembers(); // returns an empty array
168
+
// the raw model data input is not affected by the filter
@@ -228,6 +287,9 @@ The callable filter method must be a static method. Internally it will be called
228
287
229
288
If the custom filter is added to the generator configuration you can now use the filter in your schema and the generator will resolve the function:
230
289
290
+
.. hint::
291
+
292
+
If a filter with the token of your custom filter already exists the existing filter will be overwritten when adding the filter to the generator configuration. By overwriting filters you may change the behaviour of builtin filters by replacing them with your custom implementation.
0 commit comments