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/complexTypes/object.rst
+45-1Lines changed: 45 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -514,4 +514,48 @@ Multiple violations against the schema dependency may be included.
514
514
Pattern Properties
515
515
------------------
516
516
517
-
Pattern properties are currently not supported.
517
+
Using the keyword `patternProperties` further restrictions for properties matching a pattern can be defined.
518
+
519
+
.. hint::
520
+
521
+
If you define constraints via `patternProperties` you may want to use the `PatternPropertiesAccessorPostProcessor <../generator/postProcessor.html#patternpropertiesaccessorpostprocessor>`__ to access your pattern properties.
522
+
523
+
.. code-block:: json
524
+
525
+
{
526
+
"$id": "example",
527
+
"type": "object",
528
+
"properties": {
529
+
"example": {
530
+
"type": "integer"
531
+
}
532
+
},
533
+
"patternProperties": {
534
+
"^a": {
535
+
"type": "string"
536
+
}
537
+
}
538
+
}
539
+
540
+
Possible exceptions:
541
+
542
+
If invalid pattern properties are provided a detailed exception will be thrown containing all violations:
543
+
544
+
.. code-block:: none
545
+
546
+
Provided JSON for Example contains invalid pattern properties.
547
+
- invalid property 'a0' matching pattern '\^a'
548
+
* Invalid type for pattern property. Requires string, got integer
549
+
550
+
The thrown exception will be a *PHPModelGenerator\\Exception\\Object\\InvalidPatternPropertiesException* which provides the following methods to get further error details:
551
+
552
+
.. code-block:: php
553
+
554
+
// returns a two-dimensional array which contains all validation exceptions grouped by property names
Copy file name to clipboardExpand all lines: docs/source/generator/postProcessor.rst
+62-1Lines changed: 62 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -143,7 +143,68 @@ Generated interface with the **AdditionalPropertiesAccessorPostProcessor**:
143
143
Serialization
144
144
~~~~~~~~~~~~~
145
145
146
-
By default additional properties are not included in serialized models. If the **AdditionalPropertiesAccessorPostProcessor** is applied and `serialization <../gettingStarted.html#serialization-methods>`__ is enabled the additional properties will be merged into the serialization result. If the additional properties are processed via a transforming filter each value will be serialized via the serialisation method of the transforming filter.
146
+
By default additional properties are only included in the serialized models if the *additionalProperties* field is set to true or contains further restrictions. If the option *$addForModelsWithoutAdditionalPropertiesDefinition* is set to true also additional properties for entities which don't define the *additionalProperties* field will be included in the serialization result. If the **AdditionalPropertiesAccessorPostProcessor** is applied and `serialization <../gettingStarted.html#serialization-methods>`__ is enabled the additional properties will be merged into the serialization result. If the additional properties are processed via a transforming filter each value will be serialized via the serialisation method of the transforming filter.
The **PatternPropertiesAccessorPostProcessor** adds methods to your model to work with `pattern properties <../complexTypes/object.html#pattern-properties>`__ on your objects. The methods will only be added if the schema for the object defines pattern properties.
157
+
158
+
Added methods
159
+
~~~~~~~~~~~~~
160
+
161
+
.. code-block:: json
162
+
163
+
{
164
+
"$id": "example",
165
+
"type": "object",
166
+
"properties": {
167
+
"example": {
168
+
"type": "string"
169
+
}
170
+
},
171
+
"patternProperties": {
172
+
"^a": {
173
+
"type": "string"
174
+
},
175
+
"^b": {
176
+
"key": "numbers"
177
+
"type": "integer"
178
+
},
179
+
}
180
+
}
181
+
182
+
Generated interface with the **AdditionalPropertiesAccessorPostProcessor**:
183
+
184
+
.. code-block:: php
185
+
186
+
public function getRawModelDataInput(): array;
187
+
188
+
public function setExample(float $example): self;
189
+
public function getExample(): float;
190
+
191
+
public function getPatternProperties(string $key): array;
192
+
193
+
The added method **getPatternProperties** can be used to fetch a list of all properties matching the given pattern. As *$key* you have to provide the pattern you want to fetch. Alternatively you can define a key in your schema and use the key to fetch the properties.
194
+
195
+
.. code-block:: php
196
+
197
+
$myObject = new Example('a1' => 'Hello', 'b1' => 100);
198
+
199
+
// fetches all properties matching the pattern '^a', consequently will return ['a1' => 'Hello']
200
+
$myObject->getPatternProperties('^a');
201
+
202
+
// fetches all properties matching the pattern '^b' (which has a defined key), consequently will return ['b1' => 100]
203
+
$myObject->getPatternProperties('numbers');
204
+
205
+
.. note::
206
+
207
+
If you want to add or remove pattern properties to your object after the object instantiation you can use the `AdditionalPropertiesAccessorPostProcessor <generator/postProcessor.html#additionalpropertiesaccessorpostprocessor>`__ or the `PopulatePostProcessor <generator/postProcessor.html#populatepostprocessor>`__
0 commit comments