diff --git a/CHANGELOG.md b/CHANGELOG.md index 104dbe5e..f4ff856f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,14 @@ 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]. +## [`3.0.0`][3.0.0] + +For a full diff see [`2.0.0...3.0.0`][2.0.0...3.0.0]. + ### Changed - Required [`ergebnis/json-pointer`](https://github.com/ergebnis/json-pointer) ([#195]), by [@localheinz] +- Started using `Ergebnis\Json\Pointer\JsonPointer` instead of `Ergebnis\Json\SchemaValidator\JsonPointer` ([#200]), by [@localheinz] ## [`2.0.0`][2.0.0] @@ -48,10 +53,12 @@ For a full diff see [`dcd4cfb...1.0.0`][dcd4cfb...1.0.0]. [1.0.0]: https://github.com/ergebnis/json-schema-validator/releases/tag/1.0.0 [2.0.0]: https://github.com/ergebnis/json-schema-validator/releases/tag/2.0.0 +[3.0.0]: https://github.com/ergebnis/json-schema-validator/releases/tag/3.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...3.0.0]: https://github.com/ergebnis/json-schema-validator/compare/2.0.0...3.0.0 +[3.0.0...main]: https://github.com/ergebnis/json-schema-validator/compare/3.0.0...main [#2]: https://github.com/ergebnis/json-schema-validator/pull/2 [#3]: https://github.com/ergebnis/json-schema-validator/pull/3 @@ -71,5 +78,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 +[#200]: https://github.com/ergebnis/json-schema-validator/pull/200 [@localheinz]: https://github.com/localheinz diff --git a/psalm-baseline.xml b/psalm-baseline.xml index c881e4c9..78ef9164 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + \json_decode diff --git a/src/Exception/CanNotResolve.php b/src/Exception/CanNotResolve.php index 72541734..6c982db1 100644 --- a/src/Exception/CanNotResolve.php +++ b/src/Exception/CanNotResolve.php @@ -13,15 +13,15 @@ namespace Ergebnis\Json\SchemaValidator\Exception; -use Ergebnis\Json\SchemaValidator; +use Ergebnis\Json\Pointer; final class CanNotResolve extends \InvalidArgumentException { - public static function jsonPointer(SchemaValidator\JsonPointer $jsonPointer): self + public static function jsonPointer(Pointer\JsonPointer $jsonPointer): self { return new self(\sprintf( 'Can not resolve JSON pointer "%s".', - $jsonPointer->toString(), + $jsonPointer->toJsonString(), )); } } diff --git a/src/Exception/ResolvedToRootSchema.php b/src/Exception/ResolvedToRootSchema.php index 861e6d91..329ec1bd 100644 --- a/src/Exception/ResolvedToRootSchema.php +++ b/src/Exception/ResolvedToRootSchema.php @@ -13,15 +13,15 @@ namespace Ergebnis\Json\SchemaValidator\Exception; -use Ergebnis\Json\SchemaValidator; +use Ergebnis\Json\Pointer; final class ResolvedToRootSchema extends \RuntimeException { - public static function jsonPointer(SchemaValidator\JsonPointer $jsonPointer): self + public static function jsonPointer(Pointer\JsonPointer $jsonPointer): self { return new self(\sprintf( 'Resolved JSON pointer "%s" to root schema.', - $jsonPointer->toString(), + $jsonPointer->toJsonString(), )); } } diff --git a/src/JsonPointer.php b/src/JsonPointer.php deleted file mode 100644 index d69667b5..00000000 --- a/src/JsonPointer.php +++ /dev/null @@ -1,47 +0,0 @@ -value = $value; - } - - public static function fromString(string $value): self - { - return new self($value); - } - - public static function empty(): self - { - return new self(''); - } - - public function toString(): string - { - return $this->value; - } - - public function equals(self $other): bool - { - return $this->value === $other->value; - } -} diff --git a/src/SchemaValidator.php b/src/SchemaValidator.php index 7f987533..1c035e8b 100644 --- a/src/SchemaValidator.php +++ b/src/SchemaValidator.php @@ -13,6 +13,7 @@ namespace Ergebnis\Json\SchemaValidator; +use Ergebnis\Json\Pointer; use Ergebnis\Json\SchemaValidator\Exception\CanNotResolve; use Ergebnis\Json\SchemaValidator\Exception\ResolvedToRootSchema; use JsonSchema\Constraints; @@ -30,7 +31,7 @@ final class SchemaValidator public function validate( Json $json, Json $schema, - JsonPointer $jsonPointer + Pointer\JsonPointer $jsonPointer ): ValidationResult { $schemaDecoded = \json_decode( $schema->toString(), @@ -39,11 +40,11 @@ public function validate( $uriRetriever = new Uri\UriRetriever(); - if (!$jsonPointer->equals(JsonPointer::empty())) { + if (!$jsonPointer->equals(Pointer\JsonPointer::document())) { try { $subSchemaDecoded = $uriRetriever->resolvePointer( $schemaDecoded, - $jsonPointer->toString(), + $jsonPointer->toUriFragmentIdentifierString(), ); } catch (Exception\ResourceNotFoundException $exception) { throw CanNotResolve::jsonPointer($jsonPointer); @@ -81,7 +82,7 @@ public function validate( $validationErrors = \array_map(static function (array $error): ValidationError { return ValidationError::create( - JsonPointer::fromString($error['pointer']), + Pointer\JsonPointer::fromJsonString($error['pointer']), Message::fromString($error['message']), ); }, $originalErrors); diff --git a/src/ValidationError.php b/src/ValidationError.php index 19312538..da635054 100644 --- a/src/ValidationError.php +++ b/src/ValidationError.php @@ -13,16 +13,18 @@ namespace Ergebnis\Json\SchemaValidator; +use Ergebnis\Json\Pointer; + /** * @psalm-immutable */ final class ValidationError { - private JsonPointer $jsonPointer; + private Pointer\JsonPointer $jsonPointer; private Message $message; private function __construct( - JsonPointer $jsonPointer, + Pointer\JsonPointer $jsonPointer, Message $message ) { $this->jsonPointer = $jsonPointer; @@ -30,7 +32,7 @@ private function __construct( } public static function create( - JsonPointer $jsonPointer, + Pointer\JsonPointer $jsonPointer, Message $message ): self { return new self( @@ -39,7 +41,7 @@ public static function create( ); } - public function jsonPointer(): JsonPointer + public function jsonPointer(): Pointer\JsonPointer { return $this->jsonPointer; } diff --git a/test/Unit/Exception/CanNotResolveTest.php b/test/Unit/Exception/CanNotResolveTest.php index 28571c84..6017c952 100644 --- a/test/Unit/Exception/CanNotResolveTest.php +++ b/test/Unit/Exception/CanNotResolveTest.php @@ -13,8 +13,8 @@ namespace Ergebnis\Json\SchemaValidator\Test\Unit\Exception; +use Ergebnis\Json\Pointer; use Ergebnis\Json\SchemaValidator\Exception; -use Ergebnis\Json\SchemaValidator\JsonPointer; use PHPUnit\Framework; /** @@ -28,13 +28,13 @@ final class CanNotResolveTest extends Framework\TestCase { public function testJsonPointerReturnsException(): void { - $jsonPointer = JsonPointer::fromString('/foo/bar'); + $jsonPointer = Pointer\JsonPointer::fromJsonString('/foo/bar'); $exception = Exception\CanNotResolve::jsonPointer($jsonPointer); $expected = \sprintf( 'Can not resolve JSON pointer "%s".', - $jsonPointer->toString(), + $jsonPointer->toJsonString(), ); self::assertSame($expected, $exception->getMessage()); diff --git a/test/Unit/Exception/ResolvedToRootSchemaTest.php b/test/Unit/Exception/ResolvedToRootSchemaTest.php index 0e9955a8..8b79257a 100644 --- a/test/Unit/Exception/ResolvedToRootSchemaTest.php +++ b/test/Unit/Exception/ResolvedToRootSchemaTest.php @@ -13,28 +13,26 @@ namespace Ergebnis\Json\SchemaValidator\Test\Unit\Exception; +use Ergebnis\Json\Pointer; use Ergebnis\Json\SchemaValidator\Exception; -use Ergebnis\Json\SchemaValidator\JsonPointer; use PHPUnit\Framework; /** * @internal * * @covers \Ergebnis\Json\SchemaValidator\Exception\ResolvedToRootSchema - * - * @uses \Ergebnis\Json\SchemaValidator\JsonPointer */ final class ResolvedToRootSchemaTest extends Framework\TestCase { public function testJsonPointerReturnsException(): void { - $jsonPointer = JsonPointer::fromString('/foo/bar'); + $jsonPointer = Pointer\JsonPointer::fromJsonString('/foo/bar'); $exception = Exception\ResolvedToRootSchema::jsonPointer($jsonPointer); $expected = \sprintf( 'Resolved JSON pointer "%s" to root schema.', - $jsonPointer->toString(), + $jsonPointer->toJsonString(), ); self::assertSame($expected, $exception->getMessage()); diff --git a/test/Unit/JsonPointerTest.php b/test/Unit/JsonPointerTest.php deleted file mode 100644 index 002321d0..00000000 --- a/test/Unit/JsonPointerTest.php +++ /dev/null @@ -1,59 +0,0 @@ -toString()); - } - - public function testEmptyReturnsJsonPointer(): void - { - $jsonPointer = JsonPointer::empty(); - - self::assertSame('', $jsonPointer->toString()); - } - - public function testEqualsReturnsFalseWhenValueIsDifferent(): void - { - $one = JsonPointer::fromString('#/foo/bar'); - $two = JsonPointer::fromString('#/foo/baz'); - - self::assertFalse($one->equals($two)); - } - - public function testEqualsReturnsTrueWhenValueIsSame(): void - { - $value = '#/foo/bar'; - - $one = JsonPointer::fromString($value); - $two = JsonPointer::fromString($value); - - self::assertTrue($one->equals($two)); - } -} diff --git a/test/Unit/SchemaValidatorTest.php b/test/Unit/SchemaValidatorTest.php index 8fe55a53..a827cee2 100644 --- a/test/Unit/SchemaValidatorTest.php +++ b/test/Unit/SchemaValidatorTest.php @@ -13,9 +13,9 @@ namespace Ergebnis\Json\SchemaValidator\Test\Unit; +use Ergebnis\Json\Pointer; use Ergebnis\Json\SchemaValidator\Exception; use Ergebnis\Json\SchemaValidator\Json; -use Ergebnis\Json\SchemaValidator\JsonPointer; use Ergebnis\Json\SchemaValidator\Message; use Ergebnis\Json\SchemaValidator\SchemaValidator; use Ergebnis\Json\SchemaValidator\Test; @@ -76,7 +76,7 @@ public function testValidateReturnsResultWhenJsonIsValidAccordingToSchemaAndJson 'type' => 'object', ])); - $jsonPointer = JsonPointer::empty(); + $jsonPointer = Pointer\JsonPointer::document(); $schemaValidator = new SchemaValidator(); @@ -127,7 +127,7 @@ public function testValidateReturnsResultWhenJsonIsNotValidAccordingToSchemaAndJ 'type' => 'object', ])); - $jsonPointer = JsonPointer::empty(); + $jsonPointer = Pointer\JsonPointer::document(); $schemaValidator = new SchemaValidator(); @@ -141,15 +141,15 @@ public function testValidateReturnsResultWhenJsonIsNotValidAccordingToSchemaAndJ $expected = [ ValidationError::create( - JsonPointer::fromString('/foo/bar'), + Pointer\JsonPointer::fromJsonString('/foo/bar'), Message::fromString('Integer value found, but a boolean is required'), ), ValidationError::create( - JsonPointer::fromString('/foo/baz'), + Pointer\JsonPointer::fromJsonString('/foo/baz'), Message::fromString('String value found, but an array is required'), ), ValidationError::create( - JsonPointer::empty(), + Pointer\JsonPointer::document(), Message::fromString('The property qux is not defined and the definition does not allow additional properties'), ), ]; @@ -192,7 +192,7 @@ public function testValidateReturnsResultWhenJsonIsValidAccordingToSchemaAndJson 'type' => 'object', ])); - $jsonPointer = JsonPointer::fromString('#/properties/foo'); + $jsonPointer = Pointer\JsonPointer::fromUriFragmentIdentifierString('#/properties/foo'); $schemaValidator = new SchemaValidator(); @@ -240,7 +240,7 @@ public function testValidateThrowsCanNotResolveWhenJsonPointerIsNotEmptyAndSubSc 'type' => 'object', ])); - $jsonPointer = JsonPointer::fromString('#/properties/qux'); + $jsonPointer = Pointer\JsonPointer::fromUriFragmentIdentifierString('#/properties/qux'); $schemaValidator = new SchemaValidator(); @@ -288,7 +288,7 @@ public function testValidateThrowsResolvedToRootSchemaWhenJsonPointerIsNotEmptyA 'type' => 'object', ])); - $jsonPointer = JsonPointer::fromString('/properties/qux'); + $jsonPointer = Pointer\JsonPointer::fromJsonString('/properties/qux'); $schemaValidator = new SchemaValidator(); @@ -336,7 +336,7 @@ public function testValidateReturnsResultWhenJsonIsNotValidAccordingToSchemaAndJ 'type' => 'object', ])); - $jsonPointer = JsonPointer::fromString('#/properties/foo'); + $jsonPointer = Pointer\JsonPointer::fromUriFragmentIdentifierString('#/properties/foo'); $schemaValidator = new SchemaValidator(); @@ -350,11 +350,11 @@ public function testValidateReturnsResultWhenJsonIsNotValidAccordingToSchemaAndJ $expected = [ ValidationError::create( - JsonPointer::fromString('/bar'), + Pointer\JsonPointer::fromJsonString('/bar'), Message::fromString('String value found, but a boolean is required'), ), ValidationError::create( - JsonPointer::fromString('/baz'), + Pointer\JsonPointer::fromJsonString('/baz'), Message::fromString('Boolean value found, but an array is required'), ), ]; diff --git a/test/Unit/ValidationErrorTest.php b/test/Unit/ValidationErrorTest.php index 453a702c..f14e58b2 100644 --- a/test/Unit/ValidationErrorTest.php +++ b/test/Unit/ValidationErrorTest.php @@ -13,7 +13,7 @@ namespace Ergebnis\Json\SchemaValidator\Test\Unit; -use Ergebnis\Json\SchemaValidator\JsonPointer; +use Ergebnis\Json\Pointer; use Ergebnis\Json\SchemaValidator\Message; use Ergebnis\Json\SchemaValidator\Test; use Ergebnis\Json\SchemaValidator\ValidationError; @@ -33,7 +33,7 @@ final class ValidationErrorTest extends Framework\TestCase public function testCreateReturnsValidationError(): void { - $jsonPointer = JsonPointer::fromString('#/foo/bar'); + $jsonPointer = Pointer\JsonPointer::fromUriFragmentIdentifierString('#/foo/bar'); $message = Message::fromString(self::faker()->sentence()); $validationError = ValidationError::create( diff --git a/test/Unit/ValidationResultTest.php b/test/Unit/ValidationResultTest.php index 3c634a04..c2abf48d 100644 --- a/test/Unit/ValidationResultTest.php +++ b/test/Unit/ValidationResultTest.php @@ -13,7 +13,7 @@ namespace Ergebnis\Json\SchemaValidator\Test\Unit; -use Ergebnis\Json\SchemaValidator\JsonPointer; +use Ergebnis\Json\Pointer; use Ergebnis\Json\SchemaValidator\Message; use Ergebnis\Json\SchemaValidator\Test; use Ergebnis\Json\SchemaValidator\ValidationError; @@ -47,15 +47,15 @@ public function testCreateReturnsValidationResultWithErrors(): void $errors = [ ValidationError::create( - JsonPointer::fromString('/foo'), + Pointer\JsonPointer::fromJsonString('/foo'), Message::fromString($faker->sentence()), ), ValidationError::create( - JsonPointer::fromString('/bar'), + Pointer\JsonPointer::fromJsonString('/bar'), Message::fromString($faker->sentence()), ), ValidationError::create( - JsonPointer::fromString('/baz'), + Pointer\JsonPointer::fromJsonString('/baz'), Message::fromString($faker->sentence()), ), ];