Skip to content

Commit

Permalink
Fix: Throw CanNotResolve instead of ResolvedToRootSchema when JSON po…
Browse files Browse the repository at this point in the history
…inter is invalid
  • Loading branch information
localheinz committed Jan 30, 2022
1 parent e05587c commit 6b07223
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

For a full diff see [`2.0.0...main`][2.0.0...main].

### Fixed

- 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]

### Changed

- Required [`ergebnis/json-pointer`](https://github.com/ergebnis/json-pointer) ([#195]), by [@localheinz]
Expand Down Expand Up @@ -71,5 +75,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
4 changes: 1 addition & 3 deletions src/SchemaValidator.php
Expand Up @@ -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;
Expand All @@ -25,7 +24,6 @@ final class SchemaValidator
{
/**
* @throws CanNotResolve
* @throws ResolvedToRootSchema
*/
public function validate(
Json $json,
Expand All @@ -50,7 +48,7 @@ public function validate(
}

if ($schemaDecoded === $subSchemaDecoded) {
throw ResolvedToRootSchema::jsonPointer($jsonPointer);
throw CanNotResolve::jsonPointer($jsonPointer);
}

$schemaDecoded = $subSchemaDecoded;
Expand Down
2 changes: 1 addition & 1 deletion test/Unit/Exception/CanNotResolveTest.php
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion test/Unit/Exception/ResolvedToRootSchemaTest.php
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions test/Unit/SchemaValidatorTest.php
Expand Up @@ -253,7 +253,7 @@ public function testValidateThrowsCanNotResolveWhenJsonPointerIsNotEmptyAndSubSc
);
}

public function testValidateThrowsResolvedToRootSchemaWhenJsonPointerIsNotEmptyAndSubSchemaWasResolvedToRootSchema(): void
public function testValidateThrowsCanNotResolveWhenJsonPointerIsNotEmptyButCouldNotBeParsedAsUriFragmentIdentifierString(): void
{
$faker = self::faker();

Expand Down Expand Up @@ -292,7 +292,7 @@ public function testValidateThrowsResolvedToRootSchemaWhenJsonPointerIsNotEmptyA

$schemaValidator = new SchemaValidator();

$this->expectException(Exception\ResolvedToRootSchema::class);
$this->expectException(Exception\CanNotResolve::class);

$schemaValidator->validate(
$data,
Expand Down

0 comments on commit 6b07223

Please sign in to comment.