Loading src/SygalApi/Validator/OpenApi/OpenApiValidator.php +18 −4 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ use Laminas\Psr7Bridge\Psr7ServerRequest; use Laminas\Validator\AbstractValidator; use League\OpenAPIValidation\PSR7\Exception\ValidationFailed; use League\OpenAPIValidation\PSR7\ServerRequestValidator; use League\OpenAPIValidation\Schema\Exception\SchemaMismatch; use Webmozart\Assert\Assert; class OpenApiValidator extends AbstractValidator Loading @@ -14,6 +15,7 @@ class OpenApiValidator extends AbstractValidator public const INVALID_VALUE = 'invalidValue'; private ServerRequestValidator $serverRequestValidator; protected bool $generateShortExplanation = true; protected string $explain; /** @var array<self::ERROR_*, non-empty-string> */ Loading Loading @@ -54,11 +56,23 @@ class OpenApiValidator extends AbstractValidator private function generateMessageFromException(ValidationFailed $e): string { $message = $e->getMessage(); while ($e = $e->getPrevious()) { $message .= PHP_EOL . $e->getMessage(); // NB : Actuellement, Pégase tronque les messages d'erreurs éventuels à 2000 caractères, // donc on essaie de réduire la taille du message utile ! :-/ // on zappe l'exception englobante if ($e->getPrevious() !== null) { $e = $e->getPrevious(); } $parts = []; do { $parts[] = $e->getMessage(); if ($e instanceof SchemaMismatch) { $parts[] = '/' . implode('/', $e->dataBreadCrumb()->buildChain()); //$parts[] = 'Data : ' . \Respect\Stringifier\stringify($e->data()); // potentiellement trop long } } while ($e = $e->getPrevious()); return $message; return implode(' ', $parts); } } No newline at end of file Loading
src/SygalApi/Validator/OpenApi/OpenApiValidator.php +18 −4 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ use Laminas\Psr7Bridge\Psr7ServerRequest; use Laminas\Validator\AbstractValidator; use League\OpenAPIValidation\PSR7\Exception\ValidationFailed; use League\OpenAPIValidation\PSR7\ServerRequestValidator; use League\OpenAPIValidation\Schema\Exception\SchemaMismatch; use Webmozart\Assert\Assert; class OpenApiValidator extends AbstractValidator Loading @@ -14,6 +15,7 @@ class OpenApiValidator extends AbstractValidator public const INVALID_VALUE = 'invalidValue'; private ServerRequestValidator $serverRequestValidator; protected bool $generateShortExplanation = true; protected string $explain; /** @var array<self::ERROR_*, non-empty-string> */ Loading Loading @@ -54,11 +56,23 @@ class OpenApiValidator extends AbstractValidator private function generateMessageFromException(ValidationFailed $e): string { $message = $e->getMessage(); while ($e = $e->getPrevious()) { $message .= PHP_EOL . $e->getMessage(); // NB : Actuellement, Pégase tronque les messages d'erreurs éventuels à 2000 caractères, // donc on essaie de réduire la taille du message utile ! :-/ // on zappe l'exception englobante if ($e->getPrevious() !== null) { $e = $e->getPrevious(); } $parts = []; do { $parts[] = $e->getMessage(); if ($e instanceof SchemaMismatch) { $parts[] = '/' . implode('/', $e->dataBreadCrumb()->buildChain()); //$parts[] = 'Data : ' . \Respect\Stringifier\stringify($e->data()); // potentiellement trop long } } while ($e = $e->getPrevious()); return $message; return implode(' ', $parts); } } No newline at end of file