Skip to content

Commit

Permalink
Merge pull request #4 from oposs/validation_erros++
Browse files Browse the repository at this point in the history
Use ErrorFormatter class to format validation errors
  • Loading branch information
sirtoobii authored Mar 8, 2023
2 parents bf179f8 + 9cabd64 commit 3d460d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [0.1.2] - 2023-03-08

### Added

* Validation errors are now more useful

## [0.1.1] - 2022-12-19

### Added
Expand Down
5 changes: 3 additions & 2 deletions src/DataObjects/SchemaObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use SilverStripe\Security\Permission;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Yaml;
use Opis\JsonSchema\{Errors\ValidationError, Validator};
use Opis\JsonSchema\{Errors\ValidationError, Validator, Errors\ErrorFormatter};


/**
Expand Down Expand Up @@ -129,10 +129,11 @@ private static function validateAgainstSchema($object, string $schema, string &$
if ($ignore_invalid_data || $validation_result->isValid()) {
return true;
} else {
$formatter = new ErrorFormatter();
$error = _t(
__CLASS__ . '.DATA_DOES_NOT_COMPLY_SCHEMA',
'_Data does not comply with schema: {schema_name}, error: {validator_error}',
["validator_error" => $validation_result->error(), "schema_name" => $schema_name]
["validator_error" => join(",", $formatter->formatFlat($validation_result->error())), "schema_name" => $schema_name]
);
return false;
}
Expand Down

0 comments on commit 3d460d8

Please sign in to comment.