Skip to content

Commit 137f304

Browse files
committed
[Bugfix] Fix validating empty field list for fields query param
Closes #225
1 parent 7c0fefb commit 137f304

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
All notable changes to this project will be documented in this file. This project adheres to
44
[Semantic Versioning](http://semver.org/) and [this changelog format](http://keepachangelog.com/).
55

6+
## Unreleased
7+
8+
### Fixed
9+
10+
- [#225](https://github.com/laravel-json-api/laravel/issues/225) Fix validation of empty field list for a resource type
11+
in the `fields` query parameter, e.g. `/api/v1/employees?fields[employees]=`.
12+
613
## [2.5.1] - 2023-01-23
714

815
### Fixed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"laravel-json-api/encoder-neomerx": "^2.0.1",
3131
"laravel-json-api/exceptions": "^1.1.1",
3232
"laravel-json-api/spec": "^1.2",
33-
"laravel-json-api/validation": "^2.1.1",
33+
"laravel-json-api/validation": "^2.1.2",
3434
"laravel/framework": "^8.76|^9.0"
3535
},
3636
"require-dev": {

tests/dummy/tests/Api/V1/Posts/ReadTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,35 @@ public function testSparseFieldSets(): void
180180
$response->assertFetchedOneExact($expected)->assertIncluded([$author]);
181181
}
182182

183+
/**
184+
* @return void
185+
* @see https://github.com/laravel-json-api/laravel/issues/225
186+
*/
187+
public function testSparseFieldSetsHasEmptyFieldList(): void
188+
{
189+
$post = Post::factory()->create();
190+
191+
$expected = $this->serializer
192+
->post($post)
193+
->only('author', 'slug', 'synopsis', 'title')
194+
->replace('author', ['type' => 'users', 'id' => $post->author]);
195+
196+
$author = $this->serializer
197+
->user($post->author)
198+
->withoutAttributes()
199+
->withoutRelationships();
200+
201+
$response = $this
202+
->withoutExceptionHandling()
203+
->jsonApi('posts')
204+
->sparseFields('posts', ['author', 'slug', 'synopsis', 'title'])
205+
->sparseFields('users', [])
206+
->includePaths('author')
207+
->get(url('/api/v1/posts', $expected['id']));
208+
209+
$response->assertFetchedOneExact($expected)->assertIncluded([$author]);
210+
}
211+
183212
public function testWithCount(): void
184213
{
185214
$post = Post::factory()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy