-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from PcComponentes/feature/support-for-multiple…
…-same-messages Feature/support for multiple same messages
- Loading branch information
Showing
16 changed files
with
513 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace PcComponentes\OpenApiMessagingContext\OpenApi; | ||
|
||
final class JsonValidation | ||
{ | ||
private string $json; | ||
private ?string $errorMessage; | ||
|
||
public function __construct(string $json, ?string $errorMessage) | ||
{ | ||
$this->json = $json; | ||
$this->errorMessage = $errorMessage; | ||
} | ||
|
||
public function hasError(): bool | ||
{ | ||
return null !== $this->errorMessage; | ||
} | ||
|
||
public function json(): string | ||
{ | ||
return $this->json; | ||
} | ||
|
||
public function errorMessage(): ?string | ||
{ | ||
return $this->errorMessage; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace PcComponentes\OpenApiMessagingContext\OpenApi; | ||
|
||
final class JsonValidationCollection | ||
{ | ||
private array $jsonValidations; | ||
|
||
public function __construct(JsonValidation ...$jsonValidations) | ||
{ | ||
$this->jsonValidations = $jsonValidations; | ||
} | ||
|
||
public function hasAnyError() | ||
{ | ||
foreach ($this->jsonValidations as $theJsonValidation) { | ||
if (true === $theJsonValidation->hasError()) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function buildErrorMessage(): string | ||
{ | ||
if (false === $this->hasAnyError()) { | ||
return ''; | ||
} | ||
|
||
$validationsWithErrors = \array_filter( | ||
$this->jsonValidations, | ||
static fn(JsonValidation $elem) => $elem->hasError() | ||
); | ||
|
||
$msg = PHP_EOL; | ||
foreach ($validationsWithErrors as $index => $validation) { | ||
$msg .= sprintf('JSON message %d does not validate. ' . PHP_EOL, $index); | ||
$msg .= $validation->errorMessage(); | ||
} | ||
|
||
return $msg; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace PcComponentes\OpenApiMessagingContext\OpenApi; | ||
|
||
final class JsonValidationException extends \Exception | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace PcComponentes\OpenApiMessagingContext\OpenApi; | ||
|
||
use JsonSchema\Validator; | ||
|
||
final class JsonValidator | ||
{ | ||
private string $jsonToValidate; | ||
private JsonSchema $jsonSchema; | ||
|
||
public function __construct(string $jsonToValidate, JsonSchema $jsonSchema) | ||
{ | ||
$this->jsonToValidate = $jsonToValidate; | ||
$this->jsonSchema = $jsonSchema; | ||
} | ||
|
||
public function validate(): JsonValidation | ||
{ | ||
return $this->jsonSchema->validate($this->jsonToValidate, new Validator()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.