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 51bcbeb commit e45e39d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ 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].

## [`2.0.1`][2.0.1]

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

### 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 ([#201]), by [@localheinz]
### Changed

- Required [`ergebnis/json-pointer`](https://github.com/ergebnis/json-pointer) ([#195]), by [@localheinz]
Expand Down Expand Up @@ -51,7 +58,8 @@ For a full diff see [`dcd4cfb...1.0.0`][dcd4cfb...1.0.0].

[dcd4cfb...1.0.0]: https://github.com/ergebnis/json-schema-validator/compare/dcd4cfb...1.0.0
[1.0.0...2.0.0]: https://github.com/ergebnis/json-schema-validator/compare/1.0.0...2.0.0
[2.0.0...main]: https://github.com/ergebnis/json-schema-validator/compare/2.0.0...main
[2.0.0...2.0.1]: https://github.com/ergebnis/json-schema-validator/compare/2.0.0...2.0.1
[2.0.1...main]: https://github.com/ergebnis/json-schema-validator/compare/2.0.1...main

[#2]: https://github.com/ergebnis/json-schema-validator/pull/2
[#3]: https://github.com/ergebnis/json-schema-validator/pull/3
Expand All @@ -71,5 +79,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
[#201]: https://github.com/ergebnis/json-schema-validator/pull/201

[@localheinz]: https://github.com/localheinz
2 changes: 1 addition & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="v4.15.0@a1b5e489e6fcebe40cb804793d964e99fc347820">
<files psalm-version="4.19.0@a2ad69ae4f5ab1f7d225a8dc4e2ec2d9415ed599">
<file src="src/Json.php">
<UnusedFunctionCall occurrences="2">
<code>\json_decode</code>
Expand Down
2 changes: 1 addition & 1 deletion src/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
6 changes: 3 additions & 3 deletions test/Unit/SchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public function testValidateThrowsCanNotResolveWhenJsonPointerIsNotEmptyAndSubSc
);
}

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

Expand Down Expand Up @@ -288,11 +288,11 @@ public function testValidateThrowsResolvedToRootSchemaWhenJsonPointerIsNotEmptyA
'type' => 'object',
]));

$jsonPointer = JsonPointer::fromString('/properties/qux');
$jsonPointer = JsonPointer::fromString('#/properties/qux');

$schemaValidator = new SchemaValidator();

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

$schemaValidator->validate(
$data,
Expand Down

0 comments on commit e45e39d

Please sign in to comment.