Skip to content

Commit bf00647

Browse files
committed
Merge branch 'release/3.0.0'
2 parents 864676e + f7bd577 commit bf00647

File tree

7 files changed

+67
-21
lines changed

7 files changed

+67
-21
lines changed

.github/workflows/tests.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Tests
22

33
on:
44
push:
5-
branches: [ main, develop ]
5+
branches: [ main, develop, 3.x ]
66
pull_request:
7-
branches: [ main, develop ]
7+
branches: [ main, develop, 3.x ]
88

99
jobs:
1010
build:
@@ -14,11 +14,8 @@ jobs:
1414
strategy:
1515
fail-fast: true
1616
matrix:
17-
php: [7.4, '8.0', 8.1, 8.2]
18-
laravel: [8.76, 9]
19-
exclude:
20-
- php: 7.4
21-
laravel: 9
17+
php: [8.1, 8.2]
18+
laravel: [10]
2219

2320
steps:
2421
- name: Checkout Code

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@
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+
## [3.0.0] - 2023-02-14
7+
8+
### Changed
9+
10+
- Upgraded to Laravel 10 and set minimum PHP version to `8.1`.
11+
- **BREAKING** If using the `laravel-json-api/cursor-pagination` package, you now need to passed the schema's `id` field
12+
to the paginator's `make()` method. I.e. use `CursorPagination::make($this->id())`
13+
14+
### Fixed
15+
16+
- **BREAKING** [#190](https://github.com/laravel-json-api/laravel/issues/190) The JSON:API media type now needs to be
17+
sent in the `Accept` header for a "delete" resource request. Previously there was no checking of the `Accept` media
18+
type, so anything could be sent. This is incorrect as the JSON:API specification shows the `Accept` header as
19+
`application/vnd.api+json` for [delete resource requests.](https://jsonapi.org/format/#crud-deleting)
20+
621
## [2.6.0] - 2023-02-09
722

823
### Added

composer.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@
2323
}
2424
],
2525
"require": {
26-
"php": "^7.4|^8.0",
26+
"php": "^8.1",
2727
"ext-json": "*",
28-
"laravel-json-api/core": "^2.4",
29-
"laravel-json-api/eloquent": "^2.3",
30-
"laravel-json-api/encoder-neomerx": "^2.0.1",
31-
"laravel-json-api/exceptions": "^1.1.1",
32-
"laravel-json-api/spec": "^1.2",
33-
"laravel-json-api/validation": "^2.1.3",
34-
"laravel/framework": "^8.76|^9.0"
28+
"laravel-json-api/core": "^3.0",
29+
"laravel-json-api/eloquent": "^3.0",
30+
"laravel-json-api/encoder-neomerx": "^3.0",
31+
"laravel-json-api/exceptions": "^2.0",
32+
"laravel-json-api/spec": "^2.0",
33+
"laravel-json-api/validation": "^3.0",
34+
"laravel/framework": "^10.0"
3535
},
3636
"require-dev": {
37-
"laravel-json-api/testing": "^1.1.2",
38-
"orchestra/testbench": "^6.23|^7.0",
39-
"phpunit/phpunit": "^9.5.10"
37+
"laravel-json-api/testing": "^2.0",
38+
"orchestra/testbench": "^8.0",
39+
"phpunit/phpunit": "^9.5.28"
4040
},
4141
"autoload": {
4242
"psr-4": {
@@ -53,7 +53,7 @@
5353
},
5454
"extra": {
5555
"branch-alias": {
56-
"dev-develop": "2.x-dev"
56+
"dev-develop": "3.x-dev"
5757
},
5858
"laravel": {
5959
"aliases": {

src/Http/Controllers/Actions/Destroy.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Illuminate\Support\Facades\Auth;
2727
use LaravelJsonApi\Contracts\Routing\Route;
2828
use LaravelJsonApi\Contracts\Store\Store as StoreContract;
29+
use LaravelJsonApi\Laravel\Exceptions\HttpNotAcceptableException;
2930
use LaravelJsonApi\Laravel\Http\Requests\ResourceRequest;
3031

3132
trait Destroy
@@ -37,10 +38,26 @@ trait Destroy
3738
* @param Route $route
3839
* @param StoreContract $store
3940
* @return Response|Responsable
40-
* @throws AuthenticationException|AuthorizationException
41+
* @throws AuthenticationException|AuthorizationException|HttpNotAcceptableException
4142
*/
4243
public function destroy(Route $route, StoreContract $store)
4344
{
45+
/**
46+
* As we do not have a query request class for a delete request,
47+
* we need to manually check that the request Accept header
48+
* is the JSON:API media type.
49+
*/
50+
$acceptable = false;
51+
52+
foreach (request()->getAcceptableContentTypes() as $contentType) {
53+
if ($contentType === ResourceRequest::JSON_API_MEDIA_TYPE) {
54+
$acceptable = true;
55+
break;
56+
}
57+
}
58+
59+
throw_unless($acceptable, new HttpNotAcceptableException());
60+
4461
$request = ResourceRequest::forResourceIfExists(
4562
$resourceType = $route->resourceType()
4663
);

src/Http/Requests/FormRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class FormRequest extends BaseFormRequest
3333
/**
3434
* @var string
3535
*/
36-
protected const JSON_API_MEDIA_TYPE = 'application/vnd.api+json';
36+
public const JSON_API_MEDIA_TYPE = 'application/vnd.api+json';
3737

3838
/**
3939
* @return bool

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,20 @@ public function testForbidden(): void
102102
'id' => $this->post->getKey(),
103103
]);
104104
}
105+
106+
/**
107+
* @param string $mediaType
108+
* @return void
109+
* @dataProvider notAcceptableMediaTypeProvider
110+
*/
111+
public function testNotAcceptableMediaType(string $mediaType): void
112+
{
113+
$response = $this
114+
->actingAs($this->post->author)
115+
->jsonApi()
116+
->accept($mediaType)
117+
->delete(url('api/v1/posts', $this->post));
118+
119+
$response->assertStatus(406);
120+
}
105121
}

tests/lib/Acceptance/RequestBodyContentTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public function testDeleteWithoutBody(): void
110110
$response = $this
111111
->withoutExceptionHandling()
112112
->actingAs($post->author)
113+
->withHeader('Accept', 'application/vnd.api+json')
113114
->delete('/api/v1/posts/' . $post->getRouteKey());
114115

115116
$response->assertNoContent();

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