diff --git a/src/Service/Nelmio/DtoOADescriber.php b/src/Service/Nelmio/DtoOADescriber.php index 77aa973..cfac802 100644 --- a/src/Service/Nelmio/DtoOADescriber.php +++ b/src/Service/Nelmio/DtoOADescriber.php @@ -230,9 +230,17 @@ private function resolveProperties( ]); if (is_array($model)) { - $property->properties = $this->resolveProperties($model); - $property->type = 'object'; - $property->required = $this->resolveRequiredProperties($model); + // checking whether there is an empty index by which you can distinguish whether the model is a collection of objects or a flat object + if (is_array($model[''] ?? null)) { + $property->type = "array"; + $property->items = new Items([]); + $property->items->properties = $this->resolveProperties($model['']); + $property->items->required = $this->resolveRequiredProperties($model['']); + } else { + $property->type = 'object'; + $property->properties = $this->resolveProperties($model); + $property->required = $this->resolveRequiredProperties($model); + } } else { $assignTo = $property; @@ -338,6 +346,9 @@ private function getClassBags( } if ($item instanceof DtoTypeModel) { + if ($item->isCollection()) { // forces an empty index to make it easier to check whether an element is an array + $propertyPath .= '.'; + } $bags = DtoUtil::mergeRecursively($bags, $this->getClassBags($item, $propertyPath)); continue; diff --git a/src/Service/Validation/TypeValidationHelper.php b/src/Service/Validation/TypeValidationHelper.php index a28714f..6d8af3b 100644 --- a/src/Service/Validation/TypeValidationHelper.php +++ b/src/Service/Validation/TypeValidationHelper.php @@ -42,6 +42,7 @@ public function validateType( } $list = new ConstraintViolationList(); + // coerce and copy sub-values foreach ($subValues as $key => $value) { if (null === ($result = $this->coercionService->coerce($key, $subProperties[$key], $value))) {