[Bug]: Interface `\Opis\JsonSchema\Format::validate()` not called
Ed-leRoux opened this issue · 2 comments
Ed-leRoux commented
Replicate:
$myFormat = new class() implements \Opis\JsonSchema\Format {
public function validate($data): bool
{
return $data === 'some-string';
}
};
$validator = new Validator();
$formats = $validator->parser()->getFormatResolver();
$formats->register('string', 'my-format', $myFormat);
$schema = \Opis\JsonSchema\Helper::toJson(['type' => 'string', 'format' => 'my-format']);
$data = 'my-format';
$validator->validate($data, $schema);
This will throw an exception PHP Fatal error: Uncaught Error: Function name must be a string
From 3c21f4e0861de4bb6e19925a56e4402faa64af63 Mon Sep 17 00:00:00 2001
From: Ed <Ed-leRoux@users.noreply.github.com>
Date: Tue, 31 Aug 2021 12:39:21 +0200
Subject: [PATCH] Custom Format Implementing Format Interface
---
src/Keywords/FormatKeyword.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Keywords/FormatKeyword.php b/src/Keywords/FormatKeyword.php
index bf1d5f6..c430f01 100644
--- a/src/Keywords/FormatKeyword.php
+++ b/src/Keywords/FormatKeyword.php
@@ -56,7 +56,7 @@ public function validate(ValidationContext $context, Schema $schema): ?Validatio
}
$format = $this->types[$type];
- if ($type instanceof Format) {
+ if ($format instanceof Format) {
$ok = $format->validate($context->currentData());
} else {
$ok = $format($context->currentData());
@@ -71,4 +71,4 @@ public function validate(ValidationContext $context, Schema $schema): ?Validatio
'type' => $type,
]);
}
-}
\ No newline at end of file
+}
Ed-leRoux commented
Please let me know if I can assist with tests.