diff --git a/CHANGELOG.md b/CHANGELOG.md index 104dbe5e..22e4fc4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ For a full diff see [`2.0.0...main`][2.0.0...main]. ### Changed - Required [`ergebnis/json-pointer`](https://github.com/ergebnis/json-pointer) ([#195]), by [@localheinz] +- Started throwing an `Exception\CanNotResolve` exception instead of an `Exception\ResolvedToRootSchema` when the `JsonPointer` is not a valid URI fragment identifier representation of a JSON pointer ([#202]), by [@localheinz] ## [`2.0.0`][2.0.0] @@ -71,5 +72,6 @@ For a full diff see [`dcd4cfb...1.0.0`][dcd4cfb...1.0.0]. [#169]: https://github.com/ergebnis/json-schema-validator/pull/169 [#172]: https://github.com/ergebnis/json-schema-validator/pull/172 [#195]: https://github.com/ergebnis/json-schema-validator/pull/195 +[#202]: https://github.com/ergebnis/json-schema-validator/pull/202 [@localheinz]: https://github.com/localheinz diff --git a/src/SchemaValidator.php b/src/SchemaValidator.php index 7f987533..bb8b89b8 100644 --- a/src/SchemaValidator.php +++ b/src/SchemaValidator.php @@ -14,7 +14,6 @@ namespace Ergebnis\Json\SchemaValidator; use Ergebnis\Json\SchemaValidator\Exception\CanNotResolve; -use Ergebnis\Json\SchemaValidator\Exception\ResolvedToRootSchema; use JsonSchema\Constraints; use JsonSchema\Exception; use JsonSchema\SchemaStorage; @@ -25,7 +24,6 @@ final class SchemaValidator { /** * @throws CanNotResolve - * @throws ResolvedToRootSchema */ public function validate( Json $json, @@ -50,7 +48,7 @@ public function validate( } if ($schemaDecoded === $subSchemaDecoded) { - throw ResolvedToRootSchema::jsonPointer($jsonPointer); + throw CanNotResolve::jsonPointer($jsonPointer); } $schemaDecoded = $subSchemaDecoded; diff --git a/test/Unit/Exception/CanNotResolveTest.php b/test/Unit/Exception/CanNotResolveTest.php index 28571c84..7f8ce12d 100644 --- a/test/Unit/Exception/CanNotResolveTest.php +++ b/test/Unit/Exception/CanNotResolveTest.php @@ -28,7 +28,7 @@ final class CanNotResolveTest extends Framework\TestCase { public function testJsonPointerReturnsException(): void { - $jsonPointer = JsonPointer::fromString('/foo/bar'); + $jsonPointer = JsonPointer::fromString('#/foo/bar'); $exception = Exception\CanNotResolve::jsonPointer($jsonPointer); diff --git a/test/Unit/Exception/ResolvedToRootSchemaTest.php b/test/Unit/Exception/ResolvedToRootSchemaTest.php index 0e9955a8..2990d458 100644 --- a/test/Unit/Exception/ResolvedToRootSchemaTest.php +++ b/test/Unit/Exception/ResolvedToRootSchemaTest.php @@ -28,7 +28,7 @@ final class ResolvedToRootSchemaTest extends Framework\TestCase { public function testJsonPointerReturnsException(): void { - $jsonPointer = JsonPointer::fromString('/foo/bar'); + $jsonPointer = JsonPointer::fromString('#/foo/bar'); $exception = Exception\ResolvedToRootSchema::jsonPointer($jsonPointer); diff --git a/test/Unit/SchemaValidatorTest.php b/test/Unit/SchemaValidatorTest.php index 8fe55a53..c419d415 100644 --- a/test/Unit/SchemaValidatorTest.php +++ b/test/Unit/SchemaValidatorTest.php @@ -253,7 +253,7 @@ public function testValidateThrowsCanNotResolveWhenJsonPointerIsNotEmptyAndSubSc ); } - public function testValidateThrowsResolvedToRootSchemaWhenJsonPointerIsNotEmptyAndSubSchemaWasResolvedToRootSchema(): void + public function testValidateThrowsCanNotResolveWhenJsonPointerIsNotEmptyButCouldNotBeParsedAsUriFragmentIdentifierString(): void { $faker = self::faker(); @@ -292,7 +292,7 @@ public function testValidateThrowsResolvedToRootSchemaWhenJsonPointerIsNotEmptyA $schemaValidator = new SchemaValidator(); - $this->expectException(Exception\ResolvedToRootSchema::class); + $this->expectException(Exception\CanNotResolve::class); $schemaValidator->validate( $data,