@@ -66,10 +66,6 @@ protected function generateValidators(PropertyInterface $property, array $proper
66
66
67
67
$ availableAmount = count ($ properties );
68
68
69
- if ($ createMergedProperty ) {
70
- $ this ->createMergedProperty ($ property , $ properties );
71
- }
72
-
73
69
$ property ->addValidator (
74
70
new ComposedPropertyValidator (
75
71
$ property ,
@@ -84,8 +80,10 @@ protected function generateValidators(PropertyInterface $property, array $proper
84
80
// final value after the validations (eg. object instantiations may be performed). Otherwise (eg. a
85
81
// NotProcessor) the value must be proposed before the validation
86
82
'postPropose ' => $ this instanceof ComposedPropertiesInterface,
87
- 'onlyForDefinedValues ' => $ propertyData ['onlyForDefinedValues ' ] &&
88
- $ this instanceof ComposedPropertiesInterface,
83
+ 'mergedProperty ' =>
84
+ $ createMergedProperty ? $ this ->createMergedProperty ($ property , $ properties ) : null ,
85
+ 'onlyForDefinedValues ' =>
86
+ $ propertyData ['onlyForDefinedValues ' ] && $ this instanceof ComposedPropertiesInterface,
89
87
]
90
88
),
91
89
100
@@ -97,12 +95,12 @@ protected function generateValidators(PropertyInterface $property, array $proper
97
95
*
98
96
* Gather all nested object properties and merge them together into a single merged property
99
97
*
100
- * @param PropertyInterface $property
98
+ * @param PropertyInterface $compositionProperty
101
99
* @param CompositionPropertyDecorator[] $properties
102
100
*
103
101
* @return PropertyInterface
104
102
*/
105
- private function createMergedProperty (PropertyInterface $ property , array $ properties ): PropertyInterface
103
+ private function createMergedProperty (PropertyInterface $ compositionProperty , array $ properties ): PropertyInterface
106
104
{
107
105
$ mergedPropertySchema = new Schema ();
108
106
$ mergedClassName = sprintf ('%s_Merged_%s ' , $ this ->schemaProcessor ->getCurrentClassName (), uniqid ());
@@ -111,7 +109,13 @@ private function createMergedProperty(PropertyInterface $property, array $proper
111
109
foreach ($ properties as $ property ) {
112
110
if ($ property ->getNestedSchema ()) {
113
111
foreach ($ property ->getNestedSchema ()->getProperties () as $ nestedProperty ) {
114
- $ mergedPropertySchema ->addProperty ($ nestedProperty );
112
+ $ mergedPropertySchema ->addProperty (
113
+ // don't validate fields in merged properties. All fields were validated before corresponding to
114
+ // the defined constraints of the composition property.
115
+ (clone $ nestedProperty )->filterValidators (function () {
116
+ return false ;
117
+ })
118
+ );
115
119
}
116
120
}
117
121
}
@@ -122,7 +126,7 @@ private function createMergedProperty(PropertyInterface $property, array $proper
122
126
$ mergedPropertySchema
123
127
);
124
128
125
- $ property ->addTypeHintDecorator (new CompositionTypeHintDecorator ($ mergedProperty ));
129
+ $ compositionProperty ->addTypeHintDecorator (new CompositionTypeHintDecorator ($ mergedProperty ));
126
130
127
131
return $ mergedProperty
128
132
->addDecorator (new ObjectInstantiationDecorator ($ mergedClassName ))
0 commit comments