From 93ac1f3ae76d97e7676fb1047613d5f4a905e95e Mon Sep 17 00:00:00 2001 From: = <=> Date: Sat, 18 Feb 2023 08:13:00 +0100 Subject: [PATCH] Add getVerboseMessage to AddressValidationFailed exception --- .../Validation/AddressValidationFailed.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/PSR7/Exception/Validation/AddressValidationFailed.php b/src/PSR7/Exception/Validation/AddressValidationFailed.php index cf962b5a..8856a6cf 100644 --- a/src/PSR7/Exception/Validation/AddressValidationFailed.php +++ b/src/PSR7/Exception/Validation/AddressValidationFailed.php @@ -6,8 +6,11 @@ use League\OpenAPIValidation\PSR7\Exception\ValidationFailed; use League\OpenAPIValidation\PSR7\OperationAddress; +use League\OpenAPIValidation\Schema\Exception\SchemaMismatch; use Throwable; +use function implode; +use function rtrim; use function sprintf; abstract class AddressValidationFailed extends ValidationFailed @@ -42,6 +45,21 @@ public static function fromAddr(OperationAddress $address): self return $ex; } + public function getVerboseMessage(): string + { + $previous = $this->getPrevious(); + if (! $previous instanceof SchemaMismatch) { + return $this->getMessage(); + } + + return sprintf( + '%s. [%s in %s]', + $this->getMessage(), + rtrim($previous->getMessage(), '.'), + implode('->', $previous->dataBreadCrumb()->buildChain()) + ); + } + public function getAddress(): OperationAddress { return $this->address;