From 055b9a8019e06cedd6cae09ba65737869068d6a4 Mon Sep 17 00:00:00 2001 From: Alexey Karapetov Date: Mon, 16 Mar 2020 18:49:02 -0700 Subject: [PATCH 1/2] Allow RelatedLink in Document. Fixes #104 --- CHANGELOG.md | 9 +++++-- composer.json | 1 - src/Internal/Identifier.php | 2 +- src/Link/RelatedLink.php | 3 ++- src/PaginatedCollection.php | 2 +- test/DataDocument/ManyResourceObjectsTest.php | 27 +++++++++---------- .../SingleResourceIdentifierTest.php | 15 ++++++----- 7 files changed, 33 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d565111..3f4bc42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [2.1.2] - 2020-03-16 +### Fixed +- Related links must be allowed inside relationship documents (#104) + ## [2.1.1] - 2019-12-19 ### Fixed - ResourceIdentifier does not allow multiple meta members (#99) @@ -22,7 +26,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - v2 initial release -[Unreleased]: https://github.com/json-api-php/json-api/compare/2.1.1...HEAD -[2.2.0]: https://github.com/json-api-php/json-api/compare/2.1.0...2.1.1 +[Unreleased]: https://github.com/json-api-php/json-api/compare/2.1.2...HEAD +[2.1.2]: https://github.com/json-api-php/json-api/compare/2.1.1...2.1.2 +[2.1.1]: https://github.com/json-api-php/json-api/compare/2.1.0...2.1.1 [2.1.0]: https://github.com/json-api-php/json-api/compare/2.0.1...2.1.0 [2.0.1]: https://github.com/json-api-php/json-api/compare/2.0.0...2.0.1 diff --git a/composer.json b/composer.json index 76bbb66..ffcd77e 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,6 @@ "require": { "php": ">=7.1", "ext-json": "*" - }, "require-dev": { "phpunit/phpunit": "^7.0||^8.0", diff --git a/src/Internal/Identifier.php b/src/Internal/Identifier.php index fa435a1..f8f9e47 100644 --- a/src/Internal/Identifier.php +++ b/src/Internal/Identifier.php @@ -8,8 +8,8 @@ interface Identifier { /** - * @internal * @param array $registry + * @internal */ public function registerIn(array &$registry): void; } diff --git a/src/Link/RelatedLink.php b/src/Link/RelatedLink.php index c1924ee..1def33c 100644 --- a/src/Link/RelatedLink.php +++ b/src/Link/RelatedLink.php @@ -3,10 +3,11 @@ namespace JsonApiPhp\JsonApi\Link; use function JsonApiPhp\JsonApi\child; +use JsonApiPhp\JsonApi\Internal\DataDocumentMember; use JsonApiPhp\JsonApi\Internal\LinkTrait; use JsonApiPhp\JsonApi\Internal\RelationshipMember; -final class RelatedLink implements RelationshipMember +final class RelatedLink implements RelationshipMember, DataDocumentMember { use LinkTrait; diff --git a/src/PaginatedCollection.php b/src/PaginatedCollection.php index 15e3cc7..e59c66f 100644 --- a/src/PaginatedCollection.php +++ b/src/PaginatedCollection.php @@ -33,8 +33,8 @@ public function attachTo($o): void } /** - * @internal * @param array $registry + * @internal */ public function registerIn(array &$registry): void { diff --git a/test/DataDocument/ManyResourceObjectsTest.php b/test/DataDocument/ManyResourceObjectsTest.php index 3a2be82..730be00 100644 --- a/test/DataDocument/ManyResourceObjectsTest.php +++ b/test/DataDocument/ManyResourceObjectsTest.php @@ -5,6 +5,7 @@ use JsonApiPhp\JsonApi\Attribute; use JsonApiPhp\JsonApi\DataDocument; use JsonApiPhp\JsonApi\JsonApi; +use JsonApiPhp\JsonApi\Link\RelatedLink; use JsonApiPhp\JsonApi\Link\SelfLink; use JsonApiPhp\JsonApi\Meta; use JsonApiPhp\JsonApi\ResourceCollection; @@ -33,24 +34,23 @@ public function testExtendedDocument() ' { "data": [{ - "type": "apples", + "type": "people", "id": "1", "attributes": { - "color": "red", - "sort": "Fuji" + "name": "Martin Fowler" }, "meta": {"apple_meta": "foo"} },{ - "type": "apples", + "type": "people", "id": "2", "attributes": { - "color": "yellow", - "sort": "Gala" + "name": "Kent Beck" }, "meta": {"apple_meta": "foo"} }], "links": { - "self": "/apples" + "self": "/books/123/relationship/authors", + "related": "/books/123/authors" }, "jsonapi": { "version": "1.0" @@ -61,21 +61,20 @@ public function testExtendedDocument() new DataDocument( new ResourceCollection( new ResourceObject( - 'apples', + 'people', '1', - new Attribute('color', 'red'), - new Attribute('sort', 'Fuji'), + new Attribute('name', 'Martin Fowler'), new Meta('apple_meta', 'foo') ), new ResourceObject( - 'apples', + 'people', '2', - new Attribute('color', 'yellow'), - new Attribute('sort', 'Gala'), + new Attribute('name', 'Kent Beck'), new Meta('apple_meta', 'foo') ) ), - new SelfLink('/apples'), + new SelfLink('/books/123/relationship/authors'), + new RelatedLink('/books/123/authors'), new JsonApi(), new Meta('document_meta', 'bar') ) diff --git a/test/DataDocument/SingleResourceIdentifierTest.php b/test/DataDocument/SingleResourceIdentifierTest.php index 1d12a77..165a625 100644 --- a/test/DataDocument/SingleResourceIdentifierTest.php +++ b/test/DataDocument/SingleResourceIdentifierTest.php @@ -4,6 +4,7 @@ use JsonApiPhp\JsonApi\DataDocument; use JsonApiPhp\JsonApi\JsonApi; +use JsonApiPhp\JsonApi\Link\RelatedLink; use JsonApiPhp\JsonApi\Link\SelfLink; use JsonApiPhp\JsonApi\Meta; use JsonApiPhp\JsonApi\ResourceIdentifier; @@ -17,13 +18,13 @@ public function testMinimalDocument() ' { "data": { - "type": "apples", + "type": "companies", "id": "1" } } ', new DataDocument( - new ResourceIdentifier('apples', '1') + new ResourceIdentifier('companies', '1') ) ); } @@ -34,7 +35,7 @@ public function testExtendedDocument() ' { "data": { - "type": "apples", + "type": "companies", "id": "1", "meta": { "apple_meta": "foo", @@ -42,7 +43,8 @@ public function testExtendedDocument() } }, "links": { - "self": "/apples/1" + "self": "/books/123/relationships/publisher", + "related": "/books/123/publisher" }, "jsonapi": { "version": "1.0" @@ -52,12 +54,13 @@ public function testExtendedDocument() ', new DataDocument( new ResourceIdentifier( - 'apples', + 'companies', '1', new Meta('apple_meta', 'foo'), new Meta('bar', [42]) ), - new SelfLink('/apples/1'), + new SelfLink('/books/123/relationships/publisher'), + new RelatedLink('/books/123/publisher'), new JsonApi(), new Meta('document_meta', 'bar') ) From ee984342a145dc9a37bdecef4fd057ce735c9906 Mon Sep 17 00:00:00 2001 From: Alexey Karapetov Date: Mon, 16 Mar 2020 18:50:28 -0700 Subject: [PATCH 2/2] Typo --- test/DataDocument/ManyResourceObjectsTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/DataDocument/ManyResourceObjectsTest.php b/test/DataDocument/ManyResourceObjectsTest.php index 730be00..54736e2 100644 --- a/test/DataDocument/ManyResourceObjectsTest.php +++ b/test/DataDocument/ManyResourceObjectsTest.php @@ -49,7 +49,7 @@ public function testExtendedDocument() "meta": {"apple_meta": "foo"} }], "links": { - "self": "/books/123/relationship/authors", + "self": "/books/123/relationships/authors", "related": "/books/123/authors" }, "jsonapi": { @@ -73,7 +73,7 @@ public function testExtendedDocument() new Meta('apple_meta', 'foo') ) ), - new SelfLink('/books/123/relationship/authors'), + new SelfLink('/books/123/relationships/authors'), new RelatedLink('/books/123/authors'), new JsonApi(), new Meta('document_meta', 'bar')