Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Throw CanNotResolve instead of ResolvedToRootSchema when JSON pointer is invalid #202

Merged
merged 1 commit into from Jan 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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]

Expand Down Expand Up @@ -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
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