Skip to content

Commit

Permalink
allow deep paths (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
spuf committed Jun 23, 2022
1 parent 17fadd1 commit da9ef85
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/Services/Mapper/ModelValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,23 @@ private function normalizeConstraintViolationPath(ConstraintViolationInterface $
$path = str_replace(['[', ']'], ['.', ''], $path);
}

$pathParts = explode('.', $path);
$lastPartKey = array_key_last($pathParts);

$isProperty = $this->hasProperty($constraintViolation->getRoot(), $pathParts[$lastPartKey]);
$isItemOfCollection = is_numeric($pathParts[$lastPartKey]);

if (!$isProperty && !$isItemOfCollection) {
$pathParts[$lastPartKey] = '*';
$path = implode('.', $pathParts);
$pathParts = [];
$schema = $this->schemaResolver->resolve(get_class($constraintViolation->getRoot()));
foreach (explode('.', $path) as $part) {
$property = $schema->properties[$part] ?? null;
if ($property instanceof RestApiBundle\Model\Mapper\Schema) {
$pathParts[] = $part;
$schema = $property;
} elseif (is_numeric($part)) {
$pathParts[] = $part;
} else {
$pathParts[] = '*';

break;
}
}

return $path;
return implode('.', $pathParts);
}

private function hasProperty(RestApiBundle\Mapping\Mapper\ModelInterface $model, string $propertyName): bool
Expand Down

0 comments on commit da9ef85

Please sign in to comment.