|
16 | 16 | use PHPModelGenerator\Model\Property\PropertyInterface; |
17 | 17 | use PHPModelGenerator\Model\Property\PropertyType; |
18 | 18 | use PHPModelGenerator\Model\SchemaDefinition\JsonSchema; |
| 19 | +use PHPModelGenerator\Model\Validator; |
19 | 20 | use PHPModelGenerator\Model\Validator\AdditionalItemsValidator; |
20 | 21 | use PHPModelGenerator\Model\Validator\ArrayItemValidator; |
21 | 22 | use PHPModelGenerator\Model\Validator\ArrayTupleValidator; |
22 | 23 | use PHPModelGenerator\Model\Validator\PropertyTemplateValidator; |
23 | 24 | use PHPModelGenerator\Model\Validator\PropertyValidator; |
| 25 | +use PHPModelGenerator\Model\Validator\RequiredPropertyValidator; |
24 | 26 | use PHPModelGenerator\PropertyProcessor\Decorator\Property\DefaultArrayToEmptyArrayDecorator; |
25 | 27 | use PHPModelGenerator\PropertyProcessor\PropertyMetaDataCollection; |
26 | 28 | use PHPModelGenerator\PropertyProcessor\PropertyFactory; |
@@ -253,16 +255,21 @@ private function addContainsValidation(PropertyInterface $property, JsonSchema $ |
253 | 255 | return; |
254 | 256 | } |
255 | 257 |
|
| 258 | + $name = "item of array {$property->getName()}"; |
256 | 259 | // an item of the array behaves like a nested property to add item-level validation |
257 | 260 | $nestedProperty = (new PropertyFactory(new PropertyProcessorFactory())) |
258 | 261 | ->create( |
259 | | - new PropertyMetaDataCollection(), |
| 262 | + new PropertyMetaDataCollection([$name]), |
260 | 263 | $this->schemaProcessor, |
261 | 264 | $this->schema, |
262 | | - "item of array {$property->getName()}", |
| 265 | + $name, |
263 | 266 | $propertySchema->withJson($propertySchema->getJson()[self::JSON_FIELD_CONTAINS]), |
264 | 267 | ); |
265 | 268 |
|
| 269 | + $nestedProperty->filterValidators(static function (Validator $validator): bool { |
| 270 | + return !is_a($validator->getValidator(), RequiredPropertyValidator::class); |
| 271 | + }); |
| 272 | + |
266 | 273 | $property->addValidator( |
267 | 274 | new PropertyTemplateValidator( |
268 | 275 | $property, |
|
0 commit comments