Skip to content

Commit 4eb1497

Browse files
authored
Allow RelatedLink in Document. Fixes #104 (#105)
* Allow RelatedLink in Document. Fixes #104
1 parent 3323544 commit 4eb1497

7 files changed

+33
-26
lines changed

Diff for: CHANGELOG.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
## [2.1.2] - 2020-03-16
10+
### Fixed
11+
- Related links must be allowed inside relationship documents (#104)
12+
913
## [2.1.1] - 2019-12-19
1014
### Fixed
1115
- 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.
2226
### Added
2327
- v2 initial release
2428

25-
[Unreleased]: https://github.com/json-api-php/json-api/compare/2.1.1...HEAD
26-
[2.2.0]: https://github.com/json-api-php/json-api/compare/2.1.0...2.1.1
29+
[Unreleased]: https://github.com/json-api-php/json-api/compare/2.1.2...HEAD
30+
[2.1.2]: https://github.com/json-api-php/json-api/compare/2.1.1...2.1.2
31+
[2.1.1]: https://github.com/json-api-php/json-api/compare/2.1.0...2.1.1
2732
[2.1.0]: https://github.com/json-api-php/json-api/compare/2.0.1...2.1.0
2833
[2.0.1]: https://github.com/json-api-php/json-api/compare/2.0.0...2.0.1

Diff for: composer.json

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"require": {
1414
"php": ">=7.1",
1515
"ext-json": "*"
16-
1716
},
1817
"require-dev": {
1918
"phpunit/phpunit": "^7.0||^8.0",

Diff for: src/Internal/Identifier.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
interface Identifier
99
{
1010
/**
11-
* @internal
1211
* @param array $registry
12+
* @internal
1313
*/
1414
public function registerIn(array &$registry): void;
1515
}

Diff for: src/Link/RelatedLink.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
namespace JsonApiPhp\JsonApi\Link;
44

55
use function JsonApiPhp\JsonApi\child;
6+
use JsonApiPhp\JsonApi\Internal\DataDocumentMember;
67
use JsonApiPhp\JsonApi\Internal\LinkTrait;
78
use JsonApiPhp\JsonApi\Internal\RelationshipMember;
89

9-
final class RelatedLink implements RelationshipMember
10+
final class RelatedLink implements RelationshipMember, DataDocumentMember
1011
{
1112
use LinkTrait;
1213

Diff for: src/PaginatedCollection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public function attachTo($o): void
3333
}
3434

3535
/**
36-
* @internal
3736
* @param array $registry
37+
* @internal
3838
*/
3939
public function registerIn(array &$registry): void
4040
{

Diff for: test/DataDocument/ManyResourceObjectsTest.php

+13-14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use JsonApiPhp\JsonApi\Attribute;
66
use JsonApiPhp\JsonApi\DataDocument;
77
use JsonApiPhp\JsonApi\JsonApi;
8+
use JsonApiPhp\JsonApi\Link\RelatedLink;
89
use JsonApiPhp\JsonApi\Link\SelfLink;
910
use JsonApiPhp\JsonApi\Meta;
1011
use JsonApiPhp\JsonApi\ResourceCollection;
@@ -33,24 +34,23 @@ public function testExtendedDocument()
3334
'
3435
{
3536
"data": [{
36-
"type": "apples",
37+
"type": "people",
3738
"id": "1",
3839
"attributes": {
39-
"color": "red",
40-
"sort": "Fuji"
40+
"name": "Martin Fowler"
4141
},
4242
"meta": {"apple_meta": "foo"}
4343
},{
44-
"type": "apples",
44+
"type": "people",
4545
"id": "2",
4646
"attributes": {
47-
"color": "yellow",
48-
"sort": "Gala"
47+
"name": "Kent Beck"
4948
},
5049
"meta": {"apple_meta": "foo"}
5150
}],
5251
"links": {
53-
"self": "/apples"
52+
"self": "/books/123/relationships/authors",
53+
"related": "/books/123/authors"
5454
},
5555
"jsonapi": {
5656
"version": "1.0"
@@ -61,21 +61,20 @@ public function testExtendedDocument()
6161
new DataDocument(
6262
new ResourceCollection(
6363
new ResourceObject(
64-
'apples',
64+
'people',
6565
'1',
66-
new Attribute('color', 'red'),
67-
new Attribute('sort', 'Fuji'),
66+
new Attribute('name', 'Martin Fowler'),
6867
new Meta('apple_meta', 'foo')
6968
),
7069
new ResourceObject(
71-
'apples',
70+
'people',
7271
'2',
73-
new Attribute('color', 'yellow'),
74-
new Attribute('sort', 'Gala'),
72+
new Attribute('name', 'Kent Beck'),
7573
new Meta('apple_meta', 'foo')
7674
)
7775
),
78-
new SelfLink('/apples'),
76+
new SelfLink('/books/123/relationships/authors'),
77+
new RelatedLink('/books/123/authors'),
7978
new JsonApi(),
8079
new Meta('document_meta', 'bar')
8180
)

Diff for: test/DataDocument/SingleResourceIdentifierTest.php

+9-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use JsonApiPhp\JsonApi\DataDocument;
66
use JsonApiPhp\JsonApi\JsonApi;
7+
use JsonApiPhp\JsonApi\Link\RelatedLink;
78
use JsonApiPhp\JsonApi\Link\SelfLink;
89
use JsonApiPhp\JsonApi\Meta;
910
use JsonApiPhp\JsonApi\ResourceIdentifier;
@@ -17,13 +18,13 @@ public function testMinimalDocument()
1718
'
1819
{
1920
"data": {
20-
"type": "apples",
21+
"type": "companies",
2122
"id": "1"
2223
}
2324
}
2425
',
2526
new DataDocument(
26-
new ResourceIdentifier('apples', '1')
27+
new ResourceIdentifier('companies', '1')
2728
)
2829
);
2930
}
@@ -34,15 +35,16 @@ public function testExtendedDocument()
3435
'
3536
{
3637
"data": {
37-
"type": "apples",
38+
"type": "companies",
3839
"id": "1",
3940
"meta": {
4041
"apple_meta": "foo",
4142
"bar": [42]
4243
}
4344
},
4445
"links": {
45-
"self": "/apples/1"
46+
"self": "/books/123/relationships/publisher",
47+
"related": "/books/123/publisher"
4648
},
4749
"jsonapi": {
4850
"version": "1.0"
@@ -52,12 +54,13 @@ public function testExtendedDocument()
5254
',
5355
new DataDocument(
5456
new ResourceIdentifier(
55-
'apples',
57+
'companies',
5658
'1',
5759
new Meta('apple_meta', 'foo'),
5860
new Meta('bar', [42])
5961
),
60-
new SelfLink('/apples/1'),
62+
new SelfLink('/books/123/relationships/publisher'),
63+
new RelatedLink('/books/123/publisher'),
6164
new JsonApi(),
6265
new Meta('document_meta', 'bar')
6366
)

0 commit comments

Comments
 (0)