From da975ac307aea75e4a41a2c32b38bafcdc2e62b4 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 11 Oct 2023 20:02:30 +1100 Subject: [PATCH 1/8] wip --- README.md | 27 +- src/JsonApiResource.php | 17 +- src/JsonApiServerImplementation.php | 2 +- src/Link.php | 2 +- src/RelationshipObject.php | 4 +- src/ResourceIdentifier.php | 2 +- tests/Feature/AttributesTest.php | 57 ---- tests/Feature/FeatureTest.php | 7 - tests/Feature/JsonApiTest.php | 66 +---- tests/Feature/RelationshipsTest.php | 286 ------------------- tests/Feature/ResourceIdentificationTest.php | 37 +-- tests/Unit/AttributesAsPropertiesTest.php | 8 +- tests/Unit/LinkTest.php | 10 +- tests/Unit/RelationshipObjectTest.php | 12 +- tests/Unit/RelationshipsAsPropertiesTest.php | 26 +- tests/Unit/ResourceIdentifierTest.php | 8 +- tests/Unit/ServerApiImplementationTest.php | 8 +- 17 files changed, 63 insertions(+), 516 deletions(-) diff --git a/README.md b/README.md index 8a231a5..e3df353 100644 --- a/README.md +++ b/README.md @@ -415,15 +415,10 @@ GET /posts?include=author&fields[posts]=title,excerpt&fields[users]=name "author": { "data": { "type": "users", - "id": "74812", - "meta": {} - }, - "meta": {}, - "links": {} + "id": "74812" + } } - }, - "meta": {}, - "links": {} + } }, { "id": "39974", @@ -436,15 +431,10 @@ GET /posts?include=author&fields[posts]=title,excerpt&fields[users]=name "author": { "data": { "type": "users", - "id": "74812", - "meta": {} - }, - "meta": {}, - "links": {} + "id": "74812" + } } - }, - "meta": {}, - "links": {} + } } ], "included": [ @@ -453,10 +443,7 @@ GET /posts?include=author&fields[posts]=title,excerpt&fields[users]=name "id": "74812", "attributes": { "name": "Tim" - }, - "relationships": {}, - "meta": {}, - "links": {} + } } ] } diff --git a/src/JsonApiResource.php b/src/JsonApiResource.php index 9f5031d..ef7e784 100644 --- a/src/JsonApiResource.php +++ b/src/JsonApiResource.php @@ -118,17 +118,19 @@ public function toResourceIdentifier(Request $request) * @api * * @param Request $request - * @return array{id: string, type: string, attributes: stdClass, relationships: stdClass, meta: stdClass, links: stdClass} + * @return array{id: string, type: string, attributes?: stdClass, relationships?: stdClass, meta?: stdClass, links?: stdClass} */ public function toArray($request) { return [ 'id' => $this->resolveId($request), 'type' => $this->resolveType($request), - 'attributes' => (object) $this->requestedAttributes($request)->all(), - 'relationships' => (object) $this->requestedRelationshipsAsIdentifiers($request)->all(), - 'meta' => (object) array_merge($this->toMeta($request), $this->meta), - 'links' => (object) self::parseLinks(array_merge($this->toLinks($request), $this->links)), + ...Collection::make([ + 'attributes' => $this->requestedAttributes($request)->all(), + 'relationships' => $this->requestedRelationshipsAsIdentifiers($request)->all(), + 'links' => self::parseLinks(array_merge($this->toLinks($request), $this->links)), + 'meta' => array_merge($this->toMeta($request), $this->meta), + ])->filter()->map(fn ($value) => (object) $value)->all(), ]; } @@ -141,9 +143,10 @@ public function toArray($request) public function with($request) { return [ - 'included' => $this->included($request) + ...$included = $this->included($request) ->uniqueStrict(fn (JsonApiResource $resource): string => $resource->toUniqueResourceIdentifier($request)) - ->values(), + ->values() + ->all() ? ['included' => $included] : [], 'jsonapi' => self::serverImplementationResolver()($request), ]; } diff --git a/src/JsonApiServerImplementation.php b/src/JsonApiServerImplementation.php index c571c84..5f12115 100644 --- a/src/JsonApiServerImplementation.php +++ b/src/JsonApiServerImplementation.php @@ -32,7 +32,7 @@ public function jsonSerialize(): array { return [ 'version' => $this->version, - 'meta' => (object) $this->meta, + ...$this->meta ? ['meta' => (object) $this->meta] : [], ]; } } diff --git a/src/Link.php b/src/Link.php index 15ec8b2..ebb842c 100644 --- a/src/Link.php +++ b/src/Link.php @@ -66,7 +66,7 @@ public function jsonSerialize(): array { return [ 'href' => $this->href, - 'meta' => (object) $this->meta, + ...$this->meta ? ['meta' => (object) $this->meta] : [], ]; } } diff --git a/src/RelationshipObject.php b/src/RelationshipObject.php index ecb336a..2c148bd 100644 --- a/src/RelationshipObject.php +++ b/src/RelationshipObject.php @@ -70,8 +70,8 @@ public function jsonSerialize(): array { return [ 'data' => $this->data, - 'meta' => (object) $this->meta, - 'links' => (object) self::parseLinks($this->links), + ...$this->meta ? ['meta' => (object) $this->meta] : [], + ...$this->links ? ['links' => (object) self::parseLinks($this->links)] : [], ]; } } diff --git a/src/ResourceIdentifier.php b/src/ResourceIdentifier.php index 67b1908..f2bd148 100644 --- a/src/ResourceIdentifier.php +++ b/src/ResourceIdentifier.php @@ -45,7 +45,7 @@ public function jsonSerialize(): array return [ 'type' => $this->type, 'id' => $this->id, - 'meta' => (object) $this->meta, + ...$this->meta ? ['meta' => (object) $this->meta] : [], ]; } } diff --git a/tests/Feature/AttributesTest.php b/tests/Feature/AttributesTest.php index 12d1713..46e88c4 100644 --- a/tests/Feature/AttributesTest.php +++ b/tests/Feature/AttributesTest.php @@ -41,13 +41,9 @@ public function toAttributes($request): array 'name' => 'Tim', 'email' => 'tim@example.com', ], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [], ]); @@ -84,13 +80,9 @@ public function toAttributes($request): array 'name' => 'Tim', 'location' => 'Melbourne', ], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [], ]); @@ -123,14 +115,9 @@ public function toAttributes($request): array 'data' => [ 'id' => 'expected-id', 'type' => 'basicModels', - 'attributes' => [], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [], ]); @@ -162,13 +149,9 @@ public function toAttributes($request): array 'attributes' => [ 'location' => 'Melbourne', ], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [], ]); @@ -196,14 +179,9 @@ public function toAttributes($request): array 'data' => [ 'id' => 'expected-id', 'type' => 'basicModels', - 'attributes' => [], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [], ]); @@ -252,14 +230,9 @@ public function testItCanSpecifyMinimalAttributes(): void 'data' => [ 'type' => 'basicModels', 'id' => 'user-id', - 'attributes' => [], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [], ]); @@ -287,13 +260,9 @@ public function testItCanRequestAttributesWhenUsingMinimalAttributes() 'attributes' => [ 'name' => 'user-name', ], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [], ]); @@ -327,31 +296,23 @@ public function testItCanUseSparseFieldsetsWithIncludedCollections(): void 'data' => [ 'id' => 'user-id', 'type' => 'basicModels', - 'attributes' => [], 'relationships' => [ 'posts' => [ 'data' => [ [ 'id' => 'post-id-1', - 'meta' => [], 'type' => 'basicModels', ], [ 'id' => 'post-id-2', - 'meta' => [], 'type' => 'basicModels', ], ], - 'links' => [], - 'meta' => [], ], ], - 'meta' => [], - 'links' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [ [ @@ -360,9 +321,6 @@ public function testItCanUseSparseFieldsetsWithIncludedCollections(): void 'attributes' => [ 'title' => 'post-title-1', ], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], [ 'id' => 'post-id-2', @@ -370,9 +328,6 @@ public function testItCanUseSparseFieldsetsWithIncludedCollections(): void 'attributes' => [ 'title' => 'post-title-2', ], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], ], ]); @@ -408,13 +363,9 @@ public function toAttributes($request): array 'attributes' => [ 'email' => 'tim@example.com', ], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [], ]); @@ -452,13 +403,9 @@ public function toAttributes($request): array 'email' => 'tim@example.com', 'address' => '123 fake street', ], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [], ]); @@ -497,13 +444,9 @@ public function toAttributes($request): array 'email' => 'tim@example.com', 'address' => '123 fake street', ], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [], ]); diff --git a/tests/Feature/FeatureTest.php b/tests/Feature/FeatureTest.php index 218c1d2..230479b 100644 --- a/tests/Feature/FeatureTest.php +++ b/tests/Feature/FeatureTest.php @@ -42,9 +42,6 @@ public function testItCanPaginate(): void 'attributes' => [ 'name' => 'name-0', ], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], [ 'id' => '2', @@ -52,9 +49,6 @@ public function testItCanPaginate(): void 'attributes' => [ 'name' => 'name-1', ], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], ], 'included' => [], @@ -100,7 +94,6 @@ public function testItCanPaginate(): void ], ], 'jsonapi' => [ - 'meta' => [], 'version' => '1.0', ], ]); diff --git a/tests/Feature/JsonApiTest.php b/tests/Feature/JsonApiTest.php index 698d8ae..823e17c 100644 --- a/tests/Feature/JsonApiTest.php +++ b/tests/Feature/JsonApiTest.php @@ -36,14 +36,10 @@ public function testItCanReturnASingleResource(): void 'attributes' => [ 'name' => 'user-name', ], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], 'included' => [], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], ]); $this->assertValidJsonApi($response); @@ -74,9 +70,6 @@ public function testItCanReturnACollection(): void 'attributes' => [ 'name' => 'user-name-1', ], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], [ 'id' => 'user-id-2', @@ -84,27 +77,26 @@ public function testItCanReturnACollection(): void 'attributes' => [ 'name' => 'user-name-2', ], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], ], 'included' => [], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], ]); $this->assertValidJsonApi($response); } - public function testItCastsEmptyAttributesAndRelationshipsToAnObject(): void + public function testItExcludesEmptyAttributesAndRelationships(): void { Route::get('test-route', fn () => UserResource::make((new BasicModel(['id' => 'user-id'])))); $response = $this->getJson('test-route?fields[basicModels]='); - self::assertStringContainsString('"attributes":{},"relationships":{},"meta":{},"links":{}', $response->content()); + self::assertStringNotContainsString('"attributes"', $response->content()); + self::assertStringNotContainsString('"relationships"', $response->content()); + self::assertStringNotContainsString('"meta"', $response->content()); + self::assertStringNotContainsString('"links"', $response->content()); $this->assertValidJsonApi($response); } @@ -126,17 +118,13 @@ public function toMeta($request): array 'data' => [ 'id' => 'expected-id', 'type' => 'basicModels', - 'attributes' => [], - 'relationships' => [], 'meta' => [ 'meta-key' => 'meta-value', ], - 'links' => [], ], 'included' => [], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], ]); $this->assertValidJsonApi($response); @@ -164,9 +152,6 @@ public function toLinks($request): array 'data' => [ 'id' => 'expected-id', 'type' => 'basicModels', - 'attributes' => [], - 'relationships' => [], - 'meta' => [], 'links' => [ 'self' => [ 'href' => 'https://example.test/self', @@ -176,18 +161,15 @@ public function toLinks($request): array ], 'related' => [ 'href' => 'https://example.test/related', - 'meta' => [], ], 'home' => [ 'href' => 'https://example.test', - 'meta' => [], ], ], ], 'included' => [], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], ]); $this->assertValidJsonApi($response); @@ -224,15 +206,10 @@ public function testItCanCustomiseTheTypeResolution(): void 'data' => [ 'id' => 'expected-id', 'type' => 'Tests\\Models\\BasicModel', - 'relationships' => [], - 'attributes' => [], - 'meta' => [], - 'links' => [], ], 'included' => [], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], ]); $this->assertValidJsonApi($response); @@ -251,15 +228,10 @@ public function testItCanCustomiseTheIdResolution(): void 'data' => [ 'id' => 'expected-id', 'type' => 'basicModels', - 'relationships' => [], - 'attributes' => [], - 'meta' => [], - 'links' => [], ], 'included' => [], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], ]); $this->assertValidJsonApi($response); @@ -267,31 +239,31 @@ public function testItCanCustomiseTheIdResolution(): void JsonApiResource::resolveIdNormally(); } - public function testItCastsEmptyResourceIdentifierMetaToObject(): void + public function testItExcludesEmptyResourceIdentifierMeta(): void { $relationship = new ResourceIdentifier('users', '5'); $json = json_encode($relationship); - self::assertSame('{"type":"users","id":"5","meta":{}}', $json); + self::assertSame('{"type":"users","id":"5"}', $json); } - public function testItCastsEmptyLinksMetaToObject(): void + public function testItExcludesEmptyLinksMeta(): void { $link = Link::self('https://timacdonald.me', []); $json = json_encode($link); - self::assertSame('{"href":"https:\/\/timacdonald.me","meta":{}}', $json); + self::assertSame('{"href":"https:\/\/timacdonald.me"}', $json); } - public function testItCastsEmptyImplementationMetaToObject(): void + public function testItExcludesEmptyImplementationMeta(): void { $implementation = new JsonApiServerImplementation('1.5', []); $json = json_encode($implementation); - self::assertSame('{"version":"1.5","meta":{}}', $json); + self::assertSame('{"version":"1.5"}', $json); } public function testItCanSpecifyAnImplementation(): void @@ -315,9 +287,6 @@ public function testItCanSpecifyAnImplementation(): void 'attributes' => [ 'name' => 'user-name', ], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], 'included' => [], 'jsonapi' => [ @@ -332,7 +301,7 @@ public function testItCanSpecifyAnImplementation(): void BasicJsonApiResource::resolveServerImplementationNormally(); } - public function testItCastsEmptyRelationshipLinkMetaToJsonObject() + public function testItExcludesEmptyRelationshipLinkMeta() { $resourceLink = RelationshipObject::toOne( new ResourceIdentifier('expected-type', 'expected-id') @@ -340,7 +309,7 @@ public function testItCastsEmptyRelationshipLinkMetaToJsonObject() $json = json_encode($resourceLink); - self::assertSame('{"data":{"type":"expected-type","id":"expected-id","meta":{}},"meta":{},"links":{}}', $json); + self::assertSame('{"data":{"type":"expected-type","id":"expected-id"}}', $json); } public function testItCanPopulateAllTheMetasAndAllTheLinks() @@ -581,7 +550,6 @@ public static function collection($resource): JsonApiResourceCollection 'data' => [ 'id' => 'user-id', 'type' => 'basicModels', - 'attributes' => [], 'relationships' => [ 'profile' => [ 'data' => null, @@ -696,8 +664,6 @@ public static function collection($resource): JsonApiResourceCollection [ 'id' => 'avatar-id', 'type' => 'basicModels', - 'attributes' => [], - 'relationships' => [], 'meta' => [ 'avatar-internal' => 'meta', 'avatar-external' => 'meta', @@ -720,8 +686,6 @@ public static function collection($resource): JsonApiResourceCollection [ 'id' => 'post-id-1', 'type' => 'basicModels', - 'attributes' => [], - 'relationships' => [], 'meta' => [ 'posts-internal' => 'meta', 'posts-internal-collection' => 'meta', @@ -742,15 +706,12 @@ public static function collection($resource): JsonApiResourceCollection ], 'external' => [ 'href' => 'posts.com', - 'meta' => [], ], ], ], [ 'id' => 'post-id-2', 'type' => 'basicModels', - 'attributes' => [], - 'relationships' => [], 'meta' => [ 'posts-internal' => 'meta', 'posts-internal-collection' => 'meta', @@ -771,7 +732,6 @@ public static function collection($resource): JsonApiResourceCollection ], 'external' => [ 'href' => 'posts.com', - 'meta' => [], ], ], ], diff --git a/tests/Feature/RelationshipsTest.php b/tests/Feature/RelationshipsTest.php index d59b089..5976aa3 100644 --- a/tests/Feature/RelationshipsTest.php +++ b/tests/Feature/RelationshipsTest.php @@ -56,14 +56,10 @@ public function toRelationships($request): array 'title' => 'post-title', 'content' => 'post-content', ], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], 'included' => [], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], ]); $this->assertValidJsonApi($response); @@ -98,18 +94,12 @@ public function testItCanIncludeASingleToOneResourceForASingleResource(): void 'data' => [ 'id' => 'author-id', 'type' => 'basicModels', - 'meta' => [], ], - 'links' => [], - 'meta' => [], ], ], - 'links' => [], - 'meta' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [ [ @@ -118,9 +108,6 @@ public function testItCanIncludeASingleToOneResourceForASingleResource(): void 'attributes' => [ 'name' => 'author-name', ], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], ], ]); @@ -168,27 +155,18 @@ public function testItCanIncludeNestedToOneResourcesForASingleResource(): void 'data' => [ 'id' => 'author-id', 'type' => 'basicModels', - 'meta' => [], ], - 'links' => [], - 'meta' => [], ], 'featureImage' => [ 'data' => [ 'id' => 'feature-image-id', 'type' => 'basicModels', - 'meta' => [], ], - 'links' => [], - 'meta' => [], ], ], - 'links' => [], - 'meta' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [ [ @@ -202,23 +180,15 @@ public function testItCanIncludeNestedToOneResourcesForASingleResource(): void 'data' => [ 'id' => 'avatar-id', 'type' => 'basicModels', - 'meta' => [], ], - 'links' => [], - 'meta' => [], ], 'license' => [ 'data' => [ 'id' => 'license-id', 'type' => 'basicModels', - 'meta' => [], ], - 'links' => [], - 'meta' => [], ], ], - 'links' => [], - 'meta' => [], ], [ 'id' => 'feature-image-id', @@ -226,9 +196,6 @@ public function testItCanIncludeNestedToOneResourcesForASingleResource(): void 'attributes' => [ 'url' => 'https://example.com/doggo.png', ], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], [ 'id' => 'license-id', @@ -236,9 +203,6 @@ public function testItCanIncludeNestedToOneResourcesForASingleResource(): void 'attributes' => [ 'key' => 'license-key', ], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], [ 'id' => 'avatar-id', @@ -246,9 +210,6 @@ public function testItCanIncludeNestedToOneResourcesForASingleResource(): void 'attributes' => [ 'url' => 'https://example.com/avatar.png', ], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], ], ]); @@ -287,51 +248,34 @@ public function toRelationships($request): array 'data' => [ 'id' => 'parent-id', 'type' => 'basicModels', - 'attributes' => [], 'relationships' => [ 'child' => [ 'data' => [ 'id' => 'child-id-1', 'type' => 'basicModels', - 'meta' => [], ], - 'links' => [], - 'meta' => [], ], ], - 'links' => [], - 'meta' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [ [ 'id' => 'child-id-1', 'type' => 'basicModels', - 'attributes' => [], 'relationships' => [ 'child' => [ 'data' => [ 'id' => 'child-id-2', 'type' => 'basicModels', - 'meta' => [], ], - 'links' => [], - 'meta' => [], ], ], - 'links' => [], - 'meta' => [], ], [ 'id' => 'child-id-2', 'type' => 'basicModels', - 'attributes' => [], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], ], ]); @@ -371,66 +315,44 @@ public function toRelationships($request): array 'data' => [ 'id' => 'parent-id', 'type' => 'basicModels', - 'attributes' => [], 'relationships' => [ 'child' => [ 'data' => [ 'id' => 'child-id-1', 'type' => 'basicModels', - 'meta' => [], ], - 'links' => [], - 'meta' => [], ], ], - 'meta' => [], - 'links' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [ [ 'id' => 'child-id-1', 'type' => 'basicModels', - 'attributes' => [], 'relationships' => [ 'child' => [ 'data' => [ [ 'id' => 'child-id-2', 'type' => 'basicModels', - 'meta' => [], ], [ 'id' => 'child-id-3', 'type' => 'basicModels', - 'meta' => [], ], ], - 'links' => [], - 'meta' => [], ], ], - 'meta' => [], - 'links' => [], ], [ 'id' => 'child-id-2', 'type' => 'basicModels', - 'attributes' => [], - 'relationships'=> [], - 'links' => [], - 'meta' => [], ], [ 'id' => 'child-id-3', 'type' => 'basicModels', - 'attributes' => [], - 'relationships'=> [], - 'links' => [], - 'meta' => [], ], ], ]); @@ -476,14 +398,9 @@ public function testItCanIncludeToOneResourcesForACollectionOfResources(): void 'data' => [ 'id' => 'author-id-1', 'type' => 'basicModels', - 'meta' => [], ], - 'links' => [], - 'meta' => [], ], ], - 'meta' => [], - 'links' => [], ], [ 'id' => 'post-id-2', @@ -497,19 +414,13 @@ public function testItCanIncludeToOneResourcesForACollectionOfResources(): void 'data' => [ 'id' => 'author-id-2', 'type' => 'basicModels', - 'meta' => [], ], - 'links' => [], - 'meta' => [], ], ], - 'meta' => [], - 'links' => [], ], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [ [ @@ -518,9 +429,6 @@ public function testItCanIncludeToOneResourcesForACollectionOfResources(): void 'attributes' => [ 'name' => 'author-name-1', ], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], [ 'id' => 'author-id-2', @@ -528,9 +436,6 @@ public function testItCanIncludeToOneResourcesForACollectionOfResources(): void 'attributes' => [ 'name' => 'author-name-2', ], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], ], ]); @@ -573,24 +478,17 @@ public function testItCanIncludeACollectionOfResourcesForASingleResource(): void [ 'id' => 'post-id-1', 'type' => 'basicModels', - 'meta' => [], ], [ 'id' => 'post-id-2', 'type' => 'basicModels', - 'meta' => [], ], ], - 'links' => [], - 'meta' => [], ], ], - 'meta' => [], - 'links' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [ [ @@ -600,9 +498,6 @@ public function testItCanIncludeACollectionOfResourcesForASingleResource(): void 'title' => 'post-title-1', 'content' => 'post-content-1', ], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], [ 'id' => 'post-id-2', @@ -611,9 +506,6 @@ public function testItCanIncludeACollectionOfResourcesForASingleResource(): void 'title' => 'post-title-2', 'content' => 'post-content-2', ], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], ], ]); @@ -700,20 +592,14 @@ public function testItCanIncludeAManyManyManyRelationship(): void [ 'id' => 'comment-id-1', 'type' => 'basicModels', - 'meta' => [], ], [ 'id' => 'comment-id-2', 'type' => 'basicModels', - 'meta' => [], ], ], - 'links' => [], - 'meta' => [], ], ], - 'meta' => [], - 'links' => [], ], [ 'id' => 'post-id-2', @@ -728,25 +614,18 @@ public function testItCanIncludeAManyManyManyRelationship(): void [ 'id' => 'comment-id-3', 'type' => 'basicModels', - 'meta' => [], ], [ 'id' => 'comment-id-4', 'type' => 'basicModels', - 'meta' => [], ], ], - 'links' => [], - 'meta' => [], ], ], - 'meta' => [], - 'links' => [], ], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [ [ @@ -761,20 +640,14 @@ public function testItCanIncludeAManyManyManyRelationship(): void [ 'id' => 'like-id-1', 'type' => 'basicModels', - 'meta' => [], ], [ 'id' => 'like-id-2', 'type' => 'basicModels', - 'meta' => [], ], ], - 'links' => [], - 'meta' => [], ], ], - 'meta' => [], - 'links' => [], ], [ 'id' => 'comment-id-2', @@ -788,52 +661,30 @@ public function testItCanIncludeAManyManyManyRelationship(): void [ 'id' => 'like-id-3', 'type' => 'basicModels', - 'meta' => [], ], [ 'id' => 'like-id-4', 'type' => 'basicModels', - 'meta' => [], ], ], - 'links' => [], - 'meta' => [], ], ], - 'meta' => [], - 'links' => [], ], [ 'id' => 'like-id-1', 'type' => 'basicModels', - 'attributes' => [], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], [ 'id' => 'like-id-2', 'type' => 'basicModels', - 'attributes' => [], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], [ 'id' => 'like-id-3', 'type' => 'basicModels', - 'attributes' => [], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], [ 'id' => 'like-id-4', 'type' => 'basicModels', - 'attributes' => [], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], [ 'id' => 'comment-id-3', @@ -847,20 +698,14 @@ public function testItCanIncludeAManyManyManyRelationship(): void [ 'id' => 'like-id-5', 'type' => 'basicModels', - 'meta' => [], ], [ 'id' => 'like-id-6', 'type' => 'basicModels', - 'meta' => [], ], ], - 'links' => [], - 'meta' => [], ], ], - 'links' => [], - 'meta' => [], ], [ 'id' => 'comment-id-4', @@ -874,52 +719,30 @@ public function testItCanIncludeAManyManyManyRelationship(): void [ 'id' => 'like-id-7', 'type' => 'basicModels', - 'meta' => [], ], [ 'id' => 'like-id-8', 'type' => 'basicModels', - 'meta' => [], ], ], - 'links' => [], - 'meta' => [], ], ], - 'links' => [], - 'meta' => [], ], [ 'id' => 'like-id-5', 'type' => 'basicModels', - 'attributes' => [], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], [ 'id' => 'like-id-6', 'type' => 'basicModels', - 'attributes' => [], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], [ 'id' => 'like-id-7', 'type' => 'basicModels', - 'attributes' => [], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], [ 'id' => 'like-id-8', 'type' => 'basicModels', - 'attributes' => [], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], ], ]); @@ -966,24 +789,17 @@ public function toAttributes($request): array 'data' => [ 'id' => 'post-id', 'type' => 'basicModels', - 'attributes' => [], 'relationships' => [ 'relation' => [ 'data' => [ 'id' => 'relation-id', 'type' => 'relation-type', - 'meta' => [], ], - 'links' => [], - 'meta' => [], ], ], - 'meta' => [], - 'links' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [ [ @@ -992,9 +808,6 @@ public function toAttributes($request): array 'attributes' => [ 'name' => 'expected name', ], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], ], ]); @@ -1037,14 +850,9 @@ public function testItFiltersOutDuplicateIncludesForACollectionOfResources(): vo 'data' => [ 'id' => 'avatar-id', 'type' => 'basicModels', - 'meta' => [], ], - 'links' => [], - 'meta' => [], ], ], - 'meta' => [], - 'links' => [], ], [ 'id' => 'user-id-2', @@ -1057,19 +865,13 @@ public function testItFiltersOutDuplicateIncludesForACollectionOfResources(): vo 'data' => [ 'id' => 'avatar-id', 'type' => 'basicModels', - 'meta' => [], ], - 'links' => [], - 'meta' => [], ], ], - 'meta' => [], - 'links' => [], ], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [ [ @@ -1078,9 +880,6 @@ public function testItFiltersOutDuplicateIncludesForACollectionOfResources(): vo 'attributes' => [ 'url' => 'https://example.com/avatar.png', ], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], ], ]); @@ -1122,19 +921,13 @@ public function testItFiltersOutDuplicateResourceObjectsIncludesForASingleResour [ 'id' => 'post-id', 'type' => 'basicModels', - 'meta' => [], ], ], - 'links' => [], - 'meta' => [], ], ], - 'meta' => [], - 'links' =>[], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [ [ @@ -1144,9 +937,6 @@ public function testItFiltersOutDuplicateResourceObjectsIncludesForASingleResour 'title' => 'post-title', 'content' => 'post-content', ], - 'relationships' => [], - 'meta' => [], - 'links' =>[], ], ], ]); @@ -1173,13 +963,9 @@ public function testItHasIncludedArrayWhenIncludeParameterIsPresentForASingleRes 'attributes' => [ 'name' => 'user-name', ], - 'relationships' => [], - 'meta' => [], - 'links' =>[], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [], ]); @@ -1207,14 +993,10 @@ public function testItHasIncludedArrayWhenIncludeParameterIsPresentForACollectio 'attributes' => [ 'name' => 'user-name', ], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [], ]); @@ -1241,16 +1023,11 @@ public function testItCanReturnNullForEmptyToOneRelationships(): void 'relationships' => [ 'avatar' => [ 'data' => null, - 'links' => [], - 'meta' => [], ], ], - 'meta' => [], - 'links' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [], ]); @@ -1277,16 +1054,11 @@ public function testItCanReturnAnEmptyArrayForEmptyToManyRelationships(): void 'relationships' => [ 'posts' => [ "data" => [], - "links" => [], - "meta" => [], ], ], - 'meta' => [], - 'links' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [], ]); @@ -1349,14 +1121,9 @@ public function testCollectionIncludesDoesntBecomeNumericKeyedObjectAfterFilteri 'data' => [ 'id' => '1', 'type' => 'basicModels', - 'meta' => [], ], - 'links' => [], - 'meta' => [], ], ], - 'meta' => [], - 'links' => [], ], [ 'id' => 'user-id-2', @@ -1369,14 +1136,9 @@ public function testCollectionIncludesDoesntBecomeNumericKeyedObjectAfterFilteri 'data' => [ 'id' => '1', 'type' => 'basicModels', - 'meta' => [], ], - 'links' => [], - 'meta' => [], ], ], - 'meta' => [], - 'links' => [], ], [ 'id' => 'user-id-3', @@ -1389,19 +1151,13 @@ public function testCollectionIncludesDoesntBecomeNumericKeyedObjectAfterFilteri 'data' => [ 'id' => '2', 'type' => 'basicModels', - 'meta' => [], ], - 'links' => [], - 'meta' => [], ], ], - 'meta' => [], - 'links' => [], ], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [ [ @@ -1410,9 +1166,6 @@ public function testCollectionIncludesDoesntBecomeNumericKeyedObjectAfterFilteri 'attributes' => [ 'url' => 'https://example.com/avatar1.png', ], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], [ 'id' => '2', @@ -1420,9 +1173,6 @@ public function testCollectionIncludesDoesntBecomeNumericKeyedObjectAfterFilteri 'attributes' => [ 'url' => 'https://example.com/avatar2.png', ], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], ], ]); @@ -1473,15 +1223,10 @@ public function testSingleResourceIncludesDoesntBecomeNumericKeyedObjectAfterFil [ 'id' => '2', 'type' => 'basicModels', - 'meta' => [], ], ], - 'meta' => [], - 'links' => [], ], ], - 'meta' => [], - 'links' => [], ], 'included' => [ [ @@ -1497,15 +1242,10 @@ public function testSingleResourceIncludesDoesntBecomeNumericKeyedObjectAfterFil [ 'id' => '3', 'type' => 'basicModels', - 'meta' => [], ], ], - 'meta' => [], - 'links' => [], ], ], - 'meta' => [], - 'links' => [], ], [ 'id' => '3', @@ -1513,14 +1253,10 @@ public function testSingleResourceIncludesDoesntBecomeNumericKeyedObjectAfterFil 'attributes' => [ 'content' => 'Comment 1', ], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], ] ); @@ -1552,13 +1288,9 @@ public function toRelationships($request): array 'attributes' => [ 'name' => 'user-name', ], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [], ]); @@ -1600,18 +1332,12 @@ public function toRelationships($request): array 'data' => [ 'type' => 'basicModels', 'id' => '2', - 'meta' => [], ], - 'links' => [], - 'meta' => [], ], ], - 'meta' => [], - 'links' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [ [ @@ -1620,9 +1346,6 @@ public function toRelationships($request): array 'attributes' => [ 'name' => 'relation-name', ], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], ], ]); @@ -1665,18 +1388,12 @@ public function toRelationships($request): array 'data' => [ 'type' => 'basicModels', 'id' => '2', - 'meta' => [], ], - 'links' => [], - 'meta' => [], ], ], - 'meta' => [], - 'links' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [ [ @@ -1685,9 +1402,6 @@ public function toRelationships($request): array 'attributes' => [ 'name' => 'relation-name', ], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], ], ]); diff --git a/tests/Feature/ResourceIdentificationTest.php b/tests/Feature/ResourceIdentificationTest.php index 1952012..8e8c755 100644 --- a/tests/Feature/ResourceIdentificationTest.php +++ b/tests/Feature/ResourceIdentificationTest.php @@ -29,15 +29,10 @@ public function testIt() "author": { "data": { "type": "users", - "id": "74812", - "meta": {} - }, - "meta": {}, - "links": {} + "id": "74812" + } } - }, - "meta": {}, - "links": {} + } }, { "id": "39974", @@ -50,15 +45,10 @@ public function testIt() "author": { "data": { "type": "users", - "id": "74812", - "meta": {} - }, - "meta": {}, - "links": {} + "id": "74812" + } } - }, - "meta": {}, - "links": {} + } } ], "included": [ @@ -67,10 +57,7 @@ public function testIt() "id": "74812", "attributes": { "name": "Tim" - }, - "relationships": {}, - "meta": {}, - "links": {} + } } ] } @@ -90,14 +77,9 @@ public function testItResolvesTheIdAndTypeOfAModel(): void 'data' => [ 'id' => 'user-id', 'type' => 'basicModels', - 'attributes' => [], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [], ]); @@ -120,14 +102,9 @@ public function testItCastsAModelsIntegerIdToAString(): void 'data' => [ 'id' => '55', 'type' => 'basicModels', - 'attributes' => [], - 'relationships' => [], - 'links' => [], - 'meta' => [], ], 'jsonapi' => [ 'version' => '1.0', - 'meta' => [], ], 'included' => [], ]); diff --git a/tests/Unit/AttributesAsPropertiesTest.php b/tests/Unit/AttributesAsPropertiesTest.php index 98d375b..306abfd 100644 --- a/tests/Unit/AttributesAsPropertiesTest.php +++ b/tests/Unit/AttributesAsPropertiesTest.php @@ -41,9 +41,6 @@ public function toAttributes($request) 'attributes' => [ 'content' => 'post-content', ], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], $response->getData(true)['data']); } @@ -76,9 +73,6 @@ public function toAttributes($request) 'attributes' => [ 'title' => 'expected-title', ], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], $response->getData(true)['data']); } @@ -97,6 +91,6 @@ public function getAttributesAttribute() $response = $resource->toResponse(Request::create('https://timacdonald.me')); $this->assertValidJsonApi($response->content()); - $this->assertSame([], $response->getData(true)['data']['attributes']); + $this->assertSame([], $response->getData(true)['data']['attributes'] ?? []); } } diff --git a/tests/Unit/LinkTest.php b/tests/Unit/LinkTest.php index 4af0b66..7011f5c 100644 --- a/tests/Unit/LinkTest.php +++ b/tests/Unit/LinkTest.php @@ -21,22 +21,22 @@ public function testItSerializes(): void $this->assertSame('{"href":"https:\/\/related.com","meta":{"expected":"meta"}}', $serialized); } - public function testEmptyMetaIsObject(): void + public function testEmptyMetaIsExluded(): void { $link = Link::related('https://related.com', []); $serialized = json_encode($link); - $this->assertSame('{"href":"https:\/\/related.com","meta":{}}', $serialized); + $this->assertSame('{"href":"https:\/\/related.com"}', $serialized); } - public function testMissingMetaIsObject(): void + public function testMissingMetaIsExcluded(): void { $link = Link::related('https://related.com'); $serialized = json_encode($link); - $this->assertSame('{"href":"https:\/\/related.com","meta":{}}', $serialized); + $this->assertSame('{"href":"https:\/\/related.com"}', $serialized); } public function testMetaCanBeAppended(): void @@ -70,7 +70,7 @@ public function testItCanUseHash() $links = json_encode($resource->toArray($request)['links']); - $this->assertSame('{"foo":{"href":"http:\/\/foo.com","meta":{}}}', $links); + $this->assertSame('{"foo":{"href":"http:\/\/foo.com"}}', $links); JsonApiResource::resolveIdNormally(); JsonApiResource::resolveTypeNormally(); diff --git a/tests/Unit/RelationshipObjectTest.php b/tests/Unit/RelationshipObjectTest.php index be5632e..0f29ef0 100644 --- a/tests/Unit/RelationshipObjectTest.php +++ b/tests/Unit/RelationshipObjectTest.php @@ -17,25 +17,25 @@ public function testItSerializes(): void $serialized = json_encode($link); - $this->assertSame('{"data":{"type":"expected-type","id":"expected-id","meta":{}},"meta":{"expected":"meta"},"links":{"expected":{"href":"link","meta":{}}}}', $serialized); + $this->assertSame('{"data":{"type":"expected-type","id":"expected-id"},"meta":{"expected":"meta"},"links":{"expected":{"href":"link"}}}', $serialized); } - public function testEmptyMetaAndLinksIsObject(): void + public function testEmptyMetaAndLinksIsExcluded(): void { $link = RelationshipObject::toOne(new ResourceIdentifier('expected-type', 'expected-id'), [], []); $serialized = json_encode($link); - $this->assertSame('{"data":{"type":"expected-type","id":"expected-id","meta":{}},"meta":{},"links":{}}', $serialized); + $this->assertSame('{"data":{"type":"expected-type","id":"expected-id"}}', $serialized); } - public function testMissingMetaAndLinksIsObject(): void + public function testMissingMetaAndLinksIsExcluded(): void { $link = RelationshipObject::toOne(new ResourceIdentifier('expected-type', 'expected-id')); $serialized = json_encode($link); - $this->assertSame('{"data":{"type":"expected-type","id":"expected-id","meta":{}},"meta":{},"links":{}}', $serialized); + $this->assertSame('{"data":{"type":"expected-type","id":"expected-id"}}', $serialized); } public function testMetaAndLinksCanBeAppended(): void @@ -47,6 +47,6 @@ public function testMetaAndLinksCanBeAppended(): void ->withLinks([Link::self('self.com')]) ); - $this->assertSame('{"data":[{"type":"expected-type","id":"expected-id","meta":{}}],"meta":{"original":"meta","expected":"meta","another":"one"},"links":{"related":{"href":"related.com","meta":{}},"self":{"href":"self.com","meta":{}}}}', $serialized); + $this->assertSame('{"data":[{"type":"expected-type","id":"expected-id"}],"meta":{"original":"meta","expected":"meta","another":"one"},"links":{"related":{"href":"related.com"},"self":{"href":"self.com"}}}', $serialized); } } diff --git a/tests/Unit/RelationshipsAsPropertiesTest.php b/tests/Unit/RelationshipsAsPropertiesTest.php index b171684..e623d42 100644 --- a/tests/Unit/RelationshipsAsPropertiesTest.php +++ b/tests/Unit/RelationshipsAsPropertiesTest.php @@ -47,10 +47,7 @@ public function toRelationships($request) 'data' => [ 'type' => 'basicModels', 'id' => 'author-id', - 'meta' => [], ], - 'meta' => [], - 'links' => [], ], ], $response->getData(true)['data']['relationships']); $this->assertSame([ @@ -60,9 +57,6 @@ public function toRelationships($request) 'attributes' => [ 'name' => 'author-name', ], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], ], $response->getData(true)['included']); } @@ -96,10 +90,7 @@ public function toRelationships($request) 'data' => [[ 'type' => 'basicModels', 'id' => 'comment-id', - 'meta' => [], ]], - 'meta' => [], - 'links' => [], ], ], $response->getData(true)['data']['relationships']); $this->assertSame([ @@ -109,9 +100,6 @@ public function toRelationships($request) 'attributes' => [ 'content' => 'comment-content', ], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], ], $response->getData(true)['included']); } @@ -147,10 +135,7 @@ public function toRelationships($request) 'data' => [[ 'type' => 'basicModels', 'id' => 'comment-id', - 'meta' => [], ]], - 'meta' => [], - 'links' => [], ], ], $response->getData(true)['data']['relationships']); $this->assertSame([ @@ -160,9 +145,6 @@ public function toRelationships($request) 'attributes' => [ 'content' => 'comment-content', ], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], ], $response->getData(true)['included']); } @@ -202,11 +184,8 @@ public function toRelationships($request) [ 'type' => 'basicModels', 'id' => 'post-id', - 'meta' => [], ], ], - 'meta' => [], - 'links' => [], ], ], $response->getData(true)['data']['relationships']); $this->assertSame([ @@ -217,9 +196,6 @@ public function toRelationships($request) 'title' => 'post-title', 'content' => 'post-content', ], - 'relationships' => [], - 'meta' => [], - 'links' => [], ], ], $response->getData(true)['included']); JsonApiResource::guessRelationshipResourceUsing(null); @@ -240,6 +216,6 @@ public function getRelationshipsAttribute() $response = $resource->toResponse(Request::create('https://timacdonald.me')); $this->assertValidJsonApi($response->content()); - $this->assertSame([], $response->getData(true)['data']['relationships']); + $this->assertSame([], $response->getData(true)['data']['relationships'] ?? []); } } diff --git a/tests/Unit/ResourceIdentifierTest.php b/tests/Unit/ResourceIdentifierTest.php index 4ba6b99..f627512 100644 --- a/tests/Unit/ResourceIdentifierTest.php +++ b/tests/Unit/ResourceIdentifierTest.php @@ -18,22 +18,22 @@ public function testItSerializes(): void $this->assertSame('{"type":"expected-type","id":"expected-id","meta":{"expected":"meta"}}', $serialized); } - public function testEmptyMetaIsObject(): void + public function testEmptyMetaIsExcluded(): void { $identifier = new ResourceIdentifier('expected-type', 'expected-id', []); $serialized = json_encode($identifier); - $this->assertSame('{"type":"expected-type","id":"expected-id","meta":{}}', $serialized); + $this->assertSame('{"type":"expected-type","id":"expected-id"}', $serialized); } - public function testMissingMetaIsObject(): void + public function testMissingMetaIsExcluded(): void { $identifier = new ResourceIdentifier('expected-type', 'expected-id'); $serialized = json_encode($identifier); - $this->assertSame('{"type":"expected-type","id":"expected-id","meta":{}}', $serialized); + $this->assertSame('{"type":"expected-type","id":"expected-id"}', $serialized); } public function testMetaCanBeAppended(): void diff --git a/tests/Unit/ServerApiImplementationTest.php b/tests/Unit/ServerApiImplementationTest.php index 5349157..aea6717 100644 --- a/tests/Unit/ServerApiImplementationTest.php +++ b/tests/Unit/ServerApiImplementationTest.php @@ -22,21 +22,21 @@ public function testItSerializes(): void self::assertSame('{"version":"5.0","meta":{"expected":"meta","more":"meta"}}', $json); } - public function testEmptyMetaIsObject(): void + public function testEmptyMetaIsExcluded(): void { $instance = new JsonApiServerImplementation('5.0', []); $json = json_encode($instance); - $this->assertSame('{"version":"5.0","meta":{}}', $json); + $this->assertSame('{"version":"5.0"}', $json); } - public function testMissingMetaIsObject(): void + public function testMissingMetaIsExcluded(): void { $instance = new JsonApiServerImplementation('5.0'); $json = json_encode($instance); - $this->assertSame('{"version":"5.0","meta":{}}', $json); + $this->assertSame('{"version":"5.0"}', $json); } } From 07f9afce1fc630cc4f3af1988f73da7ce48dbade Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Thu, 12 Oct 2023 07:38:42 +1100 Subject: [PATCH 2/8] wip --- src/JsonApiResource.php | 4 ++-- src/JsonApiResourceCollection.php | 5 +++-- tests/Feature/AttributesTest.php | 10 ---------- tests/Feature/FeatureTest.php | 1 - tests/Feature/JsonApiTest.php | 11 ----------- tests/Feature/RelationshipsTest.php | 6 ------ tests/Feature/ResourceIdentificationTest.php | 2 -- tests/TestCase.php | 3 +++ 8 files changed, 8 insertions(+), 34 deletions(-) diff --git a/src/JsonApiResource.php b/src/JsonApiResource.php index ef7e784..6d33cb7 100644 --- a/src/JsonApiResource.php +++ b/src/JsonApiResource.php @@ -143,10 +143,10 @@ public function toArray($request) public function with($request) { return [ - ...$included = $this->included($request) + ...($included = $this->included($request) ->uniqueStrict(fn (JsonApiResource $resource): string => $resource->toUniqueResourceIdentifier($request)) ->values() - ->all() ? ['included' => $included] : [], + ->all()) ? ['included' => $included] : [], 'jsonapi' => self::serverImplementationResolver()($request), ]; } diff --git a/src/JsonApiResourceCollection.php b/src/JsonApiResourceCollection.php index 03ce760..39ddb98 100644 --- a/src/JsonApiResourceCollection.php +++ b/src/JsonApiResourceCollection.php @@ -56,11 +56,12 @@ private function resolveResourceIdentifiers(Request $request) public function with($request) { return [ - 'included' => $this->collection + ...($included = $this->collection ->map(fn (JsonApiResource $resource): Collection => $resource->included($request)) ->flatten() ->uniqueStrict(fn (JsonApiResource $resource): string => $resource->toUniqueResourceIdentifier($request)) - ->values(), + ->values() + ->all()) ? ['included' => $included] : [], 'jsonapi' => JsonApiResource::serverImplementationResolver()($request), ]; } diff --git a/tests/Feature/AttributesTest.php b/tests/Feature/AttributesTest.php index 46e88c4..0827e3c 100644 --- a/tests/Feature/AttributesTest.php +++ b/tests/Feature/AttributesTest.php @@ -45,7 +45,6 @@ public function toAttributes($request): array 'jsonapi' => [ 'version' => '1.0', ], - 'included' => [], ]); $this->assertValidJsonApi($response); } @@ -84,7 +83,6 @@ public function toAttributes($request): array 'jsonapi' => [ 'version' => '1.0', ], - 'included' => [], ]); $this->assertValidJsonApi($response); } @@ -119,7 +117,6 @@ public function toAttributes($request): array 'jsonapi' => [ 'version' => '1.0', ], - 'included' => [], ]); $this->assertValidJsonApi($response); } @@ -153,7 +150,6 @@ public function toAttributes($request): array 'jsonapi' => [ 'version' => '1.0', ], - 'included' => [], ]); $this->assertValidJsonApi($response); } @@ -183,7 +179,6 @@ public function toAttributes($request): array 'jsonapi' => [ 'version' => '1.0', ], - 'included' => [], ]); $this->assertValidJsonApi($response); } @@ -234,7 +229,6 @@ public function testItCanSpecifyMinimalAttributes(): void 'jsonapi' => [ 'version' => '1.0', ], - 'included' => [], ]); $this->assertValidJsonApi($response); }); @@ -264,7 +258,6 @@ public function testItCanRequestAttributesWhenUsingMinimalAttributes() 'jsonapi' => [ 'version' => '1.0', ], - 'included' => [], ]); $this->assertValidJsonApi($response); }); @@ -367,7 +360,6 @@ public function toAttributes($request): array 'jsonapi' => [ 'version' => '1.0', ], - 'included' => [], ]); $this->assertValidJsonApi($response); } @@ -407,7 +399,6 @@ public function toAttributes($request): array 'jsonapi' => [ 'version' => '1.0', ], - 'included' => [], ]); $this->assertValidJsonApi($response); } @@ -448,7 +439,6 @@ public function toAttributes($request): array 'jsonapi' => [ 'version' => '1.0', ], - 'included' => [], ]); $this->assertValidJsonApi($response); } diff --git a/tests/Feature/FeatureTest.php b/tests/Feature/FeatureTest.php index 230479b..5e51795 100644 --- a/tests/Feature/FeatureTest.php +++ b/tests/Feature/FeatureTest.php @@ -51,7 +51,6 @@ public function testItCanPaginate(): void ], ], ], - 'included' => [], 'links' => [ 'first' => 'http://localhost/test-route?page=1', 'last' => 'http://localhost/test-route?page=3', diff --git a/tests/Feature/JsonApiTest.php b/tests/Feature/JsonApiTest.php index 823e17c..3c38bf2 100644 --- a/tests/Feature/JsonApiTest.php +++ b/tests/Feature/JsonApiTest.php @@ -37,7 +37,6 @@ public function testItCanReturnASingleResource(): void 'name' => 'user-name', ], ], - 'included' => [], 'jsonapi' => [ 'version' => '1.0', ], @@ -79,7 +78,6 @@ public function testItCanReturnACollection(): void ], ], ], - 'included' => [], 'jsonapi' => [ 'version' => '1.0', ], @@ -122,7 +120,6 @@ public function toMeta($request): array 'meta-key' => 'meta-value', ], ], - 'included' => [], 'jsonapi' => [ 'version' => '1.0', ], @@ -167,7 +164,6 @@ public function toLinks($request): array ], ], ], - 'included' => [], 'jsonapi' => [ 'version' => '1.0', ], @@ -207,7 +203,6 @@ public function testItCanCustomiseTheTypeResolution(): void 'id' => 'expected-id', 'type' => 'Tests\\Models\\BasicModel', ], - 'included' => [], 'jsonapi' => [ 'version' => '1.0', ], @@ -229,7 +224,6 @@ public function testItCanCustomiseTheIdResolution(): void 'id' => 'expected-id', 'type' => 'basicModels', ], - 'included' => [], 'jsonapi' => [ 'version' => '1.0', ], @@ -288,7 +282,6 @@ public function testItCanSpecifyAnImplementation(): void 'name' => 'user-name', ], ], - 'included' => [], 'jsonapi' => [ 'version' => '1.4.3', 'meta' => [ @@ -297,8 +290,6 @@ public function testItCanSpecifyAnImplementation(): void ], ]); $this->assertValidJsonApi($response); - - BasicJsonApiResource::resolveServerImplementationNormally(); } public function testItExcludesEmptyRelationshipLinkMeta() @@ -744,7 +735,5 @@ public static function collection($resource): JsonApiResourceCollection ], ]); $this->assertValidJsonApi($response); - - JsonApiResource::resolveServerImplementationNormally(); } } diff --git a/tests/Feature/RelationshipsTest.php b/tests/Feature/RelationshipsTest.php index 5976aa3..9c4facc 100644 --- a/tests/Feature/RelationshipsTest.php +++ b/tests/Feature/RelationshipsTest.php @@ -57,7 +57,6 @@ public function toRelationships($request): array 'content' => 'post-content', ], ], - 'included' => [], 'jsonapi' => [ 'version' => '1.0', ], @@ -967,7 +966,6 @@ public function testItHasIncludedArrayWhenIncludeParameterIsPresentForASingleRes 'jsonapi' => [ 'version' => '1.0', ], - 'included' => [], ]); $this->assertValidJsonApi($response); } @@ -998,7 +996,6 @@ public function testItHasIncludedArrayWhenIncludeParameterIsPresentForACollectio 'jsonapi' => [ 'version' => '1.0', ], - 'included' => [], ]); $this->assertValidJsonApi($response); } @@ -1029,7 +1026,6 @@ public function testItCanReturnNullForEmptyToOneRelationships(): void 'jsonapi' => [ 'version' => '1.0', ], - 'included' => [], ]); $this->assertValidJsonApi($response); } @@ -1060,7 +1056,6 @@ public function testItCanReturnAnEmptyArrayForEmptyToManyRelationships(): void 'jsonapi' => [ 'version' => '1.0', ], - 'included' => [], ]); $this->assertValidJsonApi($response); } @@ -1292,7 +1287,6 @@ public function toRelationships($request): array 'jsonapi' => [ 'version' => '1.0', ], - 'included' => [], ]); $this->assertValidJsonApi($response); } diff --git a/tests/Feature/ResourceIdentificationTest.php b/tests/Feature/ResourceIdentificationTest.php index 8e8c755..6ddf7e6 100644 --- a/tests/Feature/ResourceIdentificationTest.php +++ b/tests/Feature/ResourceIdentificationTest.php @@ -81,7 +81,6 @@ public function testItResolvesTheIdAndTypeOfAModel(): void 'jsonapi' => [ 'version' => '1.0', ], - 'included' => [], ]); $this->assertValidJsonApi($response); } @@ -106,7 +105,6 @@ public function testItCastsAModelsIntegerIdToAString(): void 'jsonapi' => [ 'version' => '1.0', ], - 'included' => [], ]); $this->assertValidJsonApi($response); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 3039cd7..2b49fee 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -9,6 +9,7 @@ use Orchestra\Testbench\TestCase as BaseTestCase; use RuntimeException; +use TiMacDonald\JsonApi\JsonApiResource; use function is_string; class TestCase extends BaseTestCase @@ -21,6 +22,8 @@ public function setUp(): void { parent::setUp(); + JsonApiResource::resolveServerImplementationNormally(); + $this->withoutExceptionHandling(); } From d3ef75ea735b3dba6e70028828379d4664c7e06d Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Thu, 12 Oct 2023 07:41:11 +1100 Subject: [PATCH 3/8] wip --- tests/Feature/AttributesTest.php | 2 +- tests/TestCase.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Feature/AttributesTest.php b/tests/Feature/AttributesTest.php index 0827e3c..f79e56d 100644 --- a/tests/Feature/AttributesTest.php +++ b/tests/Feature/AttributesTest.php @@ -339,7 +339,7 @@ public function testItRemovesPotentiallyMissingAttributes(): void public function toAttributes($request): array { return [ - 'name' => $this->when(false, fn () =>$this->name), + 'name' => $this->when(false, fn () => $this->name), 'address' => fn () => $this->when(false, fn () => $this->address), 'email' => $this->email, ]; diff --git a/tests/TestCase.php b/tests/TestCase.php index 2b49fee..ace7e43 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -10,6 +10,7 @@ use RuntimeException; use TiMacDonald\JsonApi\JsonApiResource; + use function is_string; class TestCase extends BaseTestCase From 5ae704fd2ff8f1802b8e04ffed19d724c8a51687 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Thu, 12 Oct 2023 07:43:26 +1100 Subject: [PATCH 4/8] wip --- src/JsonApiResource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsonApiResource.php b/src/JsonApiResource.php index 6d33cb7..c3ce83a 100644 --- a/src/JsonApiResource.php +++ b/src/JsonApiResource.php @@ -130,7 +130,7 @@ public function toArray($request) 'relationships' => $this->requestedRelationshipsAsIdentifiers($request)->all(), 'links' => self::parseLinks(array_merge($this->toLinks($request), $this->links)), 'meta' => array_merge($this->toMeta($request), $this->meta), - ])->filter()->map(fn ($value) => (object) $value)->all(), + ])->filter()->map(fn ($value) => (object) $value), ]; } From 2cb3b228d736ba5d3a0d384982f793fde3d3cef0 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Thu, 12 Oct 2023 07:44:46 +1100 Subject: [PATCH 5/8] wip --- src/JsonApiServerImplementation.php | 2 +- src/Link.php | 2 +- src/RelationshipObject.php | 2 +- src/ResourceIdentifier.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/JsonApiServerImplementation.php b/src/JsonApiServerImplementation.php index 5f12115..d4a5130 100644 --- a/src/JsonApiServerImplementation.php +++ b/src/JsonApiServerImplementation.php @@ -26,7 +26,7 @@ public function __construct(string $version, array $meta = []) /** * @internal * - * @return array{version: string, meta: stdClass} + * @return array{version: string, meta?: stdClass} */ public function jsonSerialize(): array { diff --git a/src/Link.php b/src/Link.php index ebb842c..1ab8c62 100644 --- a/src/Link.php +++ b/src/Link.php @@ -60,7 +60,7 @@ public function __construct(string $key, string $href, array $meta = []) /** * @internal * - * @return array{href: string, meta: stdClass} + * @return array{href: string, meta?: stdClass} */ public function jsonSerialize(): array { diff --git a/src/RelationshipObject.php b/src/RelationshipObject.php index 2c148bd..774b142 100644 --- a/src/RelationshipObject.php +++ b/src/RelationshipObject.php @@ -64,7 +64,7 @@ private function __construct(ResourceIdentifier|array|null $data, array $links = /** * @internal * - * @return array{data: ResourceIdentifier|null|array, meta: stdClass, links: stdClass} + * @return array{data: ResourceIdentifier|null|array, meta?: stdClass, links?: stdClass} */ public function jsonSerialize(): array { diff --git a/src/ResourceIdentifier.php b/src/ResourceIdentifier.php index f2bd148..38c2f66 100644 --- a/src/ResourceIdentifier.php +++ b/src/ResourceIdentifier.php @@ -38,7 +38,7 @@ public function __construct(string $type, string $id, array $meta = []) /** * @internal * - * @return array{type: string, id: string, meta: stdClass} + * @return array{type: string, id: string, meta?: stdClass} */ public function jsonSerialize(): array { From 9cb01b040828accd5f06215970de3e4987d0c2a1 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Thu, 12 Oct 2023 07:46:05 +1100 Subject: [PATCH 6/8] wip --- README.md | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/README.md b/README.md index e3df353..6ed9a21 100644 --- a/README.md +++ b/README.md @@ -101,9 +101,6 @@ use TiMacDonald\JsonApi\JsonApiResource; class UserResource extends JsonApiResource { - /** - * @var string[] - */ public $attributes = [ 'name', 'website', @@ -163,18 +160,12 @@ use TiMacDonald\JsonApi\JsonApiResource; class UserResource extends JsonApiResource { - /** - * @var string[] - */ public $attributes = [ 'name', 'website', 'twitter_handle', ]; - /** - * @var array> - */ public $relationships = [ 'team' => TeamResource::class, 'posts' => PostResource::class, @@ -193,18 +184,12 @@ use TiMacDonald\JsonApi\JsonApiResource; class UserResource extends JsonApiResource { - /** - * @var string[] - */ public $attributes = [ 'name', 'website', 'twitter_handle', ]; - /** - * @var string[] - */ public $relationships = [ 'team', 'posts', From b8c8094a89dbf44ad92671cd0c817df8e5ebcd42 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Thu, 12 Oct 2023 07:49:05 +1100 Subject: [PATCH 7/8] wip --- .php-cs-fixer.dist.php | 11 ++++--- tests/Feature/FeatureTest.php | 32 +++++++++---------- tests/Feature/JsonApiTest.php | 4 +-- tests/Feature/RelationshipsTest.php | 4 +-- tests/Performance/FieldsTest.php | 2 +- tests/Performance/IncludesTest.php | 2 +- .../Performance/RequestRelationshipsTest.php | 4 +-- tests/Unit/LinkTest.php | 2 +- tests/Unit/RelationshipObjectTest.php | 2 +- tests/Unit/ResourceIdentifierTest.php | 2 +- 10 files changed, 33 insertions(+), 32 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index f15aed7..a56818b 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -10,16 +10,17 @@ ->setRules([ '@PSR12' => true, '@PSR12:risky' => true, - 'no_unused_imports' => true, + 'array_indentation' => true, + 'declare_strict_types' => true, + 'explicit_string_variable' => true, 'global_namespace_import' => ['import_classes' => true, 'import_constants' => true, 'import_functions' => true], 'native_function_invocation' => true, - 'declare_strict_types' => true, + 'no_unused_imports' => true, + 'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'], + 'single_quote' => true, 'strict_comparison' => true, 'strict_param' => true, - 'explicit_string_variable' => true, 'trailing_comma_in_multiline' => true, - 'array_indentation' => true, - 'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'], ]) ->setRiskyAllowed(true) ->setFinder($finder); diff --git a/tests/Feature/FeatureTest.php b/tests/Feature/FeatureTest.php index 5e51795..fc937cf 100644 --- a/tests/Feature/FeatureTest.php +++ b/tests/Feature/FeatureTest.php @@ -64,31 +64,31 @@ public function testItCanPaginate(): void 'last_page' => 3, 'total' => 5, 'path' => 'http://localhost/test-route', - "links" => [ + 'links' => [ [ - "active" => false, - "label" => "« Previous", - "url" => null, + 'active' => false, + 'label' => '« Previous', + 'url' => null, ], [ - "active" => true, - "label" => "1", - "url" => "http://localhost/test-route?page=1", + 'active' => true, + 'label' => '1', + 'url' => 'http://localhost/test-route?page=1', ], [ - "active" => false, - "label" => "2", - "url" => "http://localhost/test-route?page=2", + 'active' => false, + 'label' => '2', + 'url' => 'http://localhost/test-route?page=2', ], [ - "active" => false, - "label" => "3", - "url" => "http://localhost/test-route?page=3", + 'active' => false, + 'label' => '3', + 'url' => 'http://localhost/test-route?page=3', ], [ - "active" => false, - "label" => "Next »", - "url" => "http://localhost/test-route?page=2", + 'active' => false, + 'label' => 'Next »', + 'url' => 'http://localhost/test-route?page=2', ], ], ], diff --git a/tests/Feature/JsonApiTest.php b/tests/Feature/JsonApiTest.php index 3c38bf2..7536b48 100644 --- a/tests/Feature/JsonApiTest.php +++ b/tests/Feature/JsonApiTest.php @@ -196,7 +196,7 @@ public function testItCanCustomiseTheTypeResolution(): void JsonApiResource::resolveTypeUsing(fn (BasicModel $model): string => $model::class); Route::get('test-route', fn () => BasicJsonApiResource::make((new BasicModel(['id' => 'expected-id'])))); - $response = $this->get("test-route"); + $response = $this->get('test-route'); $response->assertExactJson([ 'data' => [ @@ -217,7 +217,7 @@ public function testItCanCustomiseTheIdResolution(): void JsonApiResource::resolveIdUsing(fn (BasicModel $model): string => 'expected-id'); Route::get('test-route', fn () => BasicJsonApiResource::make((new BasicModel(['id' => 'missing-id'])))); - $response = $this->get("test-route"); + $response = $this->get('test-route'); $response->assertExactJson([ 'data' => [ diff --git a/tests/Feature/RelationshipsTest.php b/tests/Feature/RelationshipsTest.php index 9c4facc..1317407 100644 --- a/tests/Feature/RelationshipsTest.php +++ b/tests/Feature/RelationshipsTest.php @@ -1049,7 +1049,7 @@ public function testItCanReturnAnEmptyArrayForEmptyToManyRelationships(): void ], 'relationships' => [ 'posts' => [ - "data" => [], + 'data' => [], ], ], ], @@ -1066,7 +1066,7 @@ public function testItFlushesTheRelationshipCache(): void $resource = UserResource::make($user); Route::get('test-route', fn () => $resource); - $response = $this->get("test-route?include=posts"); + $response = $this->get('test-route?include=posts'); $response->assertOk(); $this->assertValidJsonApi($response); diff --git a/tests/Performance/FieldsTest.php b/tests/Performance/FieldsTest.php index 986cf6e..3ebcd7e 100644 --- a/tests/Performance/FieldsTest.php +++ b/tests/Performance/FieldsTest.php @@ -39,5 +39,5 @@ } $end = microtime(true); -echo "Duration (milliseconds):".PHP_EOL; +echo 'Duration (milliseconds):'.PHP_EOL; echo($end - $start) * 1000; diff --git a/tests/Performance/IncludesTest.php b/tests/Performance/IncludesTest.php index 24dd163..8a81238 100644 --- a/tests/Performance/IncludesTest.php +++ b/tests/Performance/IncludesTest.php @@ -41,5 +41,5 @@ } $end = microtime(true); -echo "Duration (milliseconds):".PHP_EOL; +echo 'Duration (milliseconds):'.PHP_EOL; echo($end - $start) * 1000; diff --git a/tests/Performance/RequestRelationshipsTest.php b/tests/Performance/RequestRelationshipsTest.php index 7d9af2e..2b5cc49 100644 --- a/tests/Performance/RequestRelationshipsTest.php +++ b/tests/Performance/RequestRelationshipsTest.php @@ -53,7 +53,7 @@ public function header(): void $modelFactory()->setRelation('author', $modelFactory())->setRelation('avatar', $modelFactory()), ]); } -$request = Request::create("https://example.com/users?include=posts.author.avatar,comments.author.avatar", 'GET'); +$request = Request::create('https://example.com/users?include=posts.author.avatar,comments.author.avatar', 'GET'); Container::getInstance()->bind('request', fn () => $request); $resource = UserResource::collection($users); @@ -61,5 +61,5 @@ public function header(): void $resource->toResponse($request); $end = microtime(true); -echo "Duration (milliseconds):".PHP_EOL; +echo 'Duration (milliseconds):'.PHP_EOL; echo($end - $start) * 1000; diff --git a/tests/Unit/LinkTest.php b/tests/Unit/LinkTest.php index 7011f5c..465acf4 100644 --- a/tests/Unit/LinkTest.php +++ b/tests/Unit/LinkTest.php @@ -44,7 +44,7 @@ public function testMetaCanBeAppended(): void $link = Link::related('https://related.com', ['original' => 'meta']); $serialized = json_encode( - $link->withMeta(['expected' => 'meta'])->withMeta(["another" => "one"]) + $link->withMeta(['expected' => 'meta'])->withMeta(['another' => 'one']) ); $this->assertSame('{"href":"https:\/\/related.com","meta":{"original":"meta","expected":"meta","another":"one"}}', $serialized); diff --git a/tests/Unit/RelationshipObjectTest.php b/tests/Unit/RelationshipObjectTest.php index 0f29ef0..7c62b6c 100644 --- a/tests/Unit/RelationshipObjectTest.php +++ b/tests/Unit/RelationshipObjectTest.php @@ -40,7 +40,7 @@ public function testMissingMetaAndLinksIsExcluded(): void public function testMetaAndLinksCanBeAppended(): void { - $link = RelationshipObject::toMany([new ResourceIdentifier('expected-type', 'expected-id')], [Link::related('related.com')], ["original" => "meta"]); + $link = RelationshipObject::toMany([new ResourceIdentifier('expected-type', 'expected-id')], [Link::related('related.com')], ['original' => 'meta']); $serialized = json_encode( $link->withMeta(['expected' => 'meta'])->withMeta(['another' => 'one']) diff --git a/tests/Unit/ResourceIdentifierTest.php b/tests/Unit/ResourceIdentifierTest.php index f627512..496ed73 100644 --- a/tests/Unit/ResourceIdentifierTest.php +++ b/tests/Unit/ResourceIdentifierTest.php @@ -41,7 +41,7 @@ public function testMetaCanBeAppended(): void $identifier = (new ResourceIdentifier('expected-type', 'expected-id', ['original' => 'meta'])); $serialized = json_encode( - $identifier->withMeta(['expected' => 'meta'])->withMeta(["another" => "one"]) + $identifier->withMeta(['expected' => 'meta'])->withMeta(['another' => 'one']) ); $this->assertSame('{"type":"expected-type","id":"expected-id","meta":{"original":"meta","expected":"meta","another":"one"}}', $serialized); From 678844d320ed924951cfa4a37242865efac7a6ae Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Thu, 12 Oct 2023 07:58:41 +1100 Subject: [PATCH 8/8] wip --- UPGRADE.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index 6ed09db..e9a412c 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -2,6 +2,12 @@ ## Upgrading To 1.x From 0.x +## Empty properties are now removed + +Previously, optional keys were always included. Optional keys are now removed from the response. This includes empty `attributes`, `relationships`, `links`, `meta`, `included`. + +This may impact consumers of your API if they are expecting those keys to be present even when empty. + ### Method visibility The following methods should now me marked as `public`: