File tree Expand file tree Collapse file tree 3 files changed +60
-0
lines changed
Bridge/Symfony/Bundle/Resources/config Expand file tree Collapse file tree 3 files changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+ Feature : JSON API Inclusion of Related Resources
2
+ In order to be able to handle inclusion of related resources
3
+ As a client software developer
4
+ I need to be able to specify include parameters according to JSON API recommendation
5
+
6
+ Background :
7
+ Given I add "Accept" header equal to "application/vnd.api+json"
8
+ And I add "Content-Type" header equal to "application/vnd.api+json"
9
+
10
+ @createSchema
11
+ @dropSchema
12
+ Scenario : Request inclusion of a related resources on collection
13
+ Given there are 3 dummy objects
14
+ When I send a "GET" request to "/dummies/1?include=foo"
15
+ Then the response status code should be 400
16
+ And the response should be in JSON
17
+
Original file line number Diff line number Diff line change 57
57
</service >
58
58
59
59
<!-- Event listener -->
60
+ <service id =" api_platform.jsonapi.listener.request.include_parameters" class =" ApiPlatform\Core\JsonApi\EventListener\IncludeParametersListener" >
61
+ <tag name =" kernel.event_listener" event =" kernel.request" method =" onKernelRequest" priority =" 5" />
62
+ </service >
60
63
61
64
<service id =" api_platform.jsonapi.listener.request.transform_pagination_parameters" class =" ApiPlatform\Core\JsonApi\EventListener\TransformPaginationParametersListener" >
62
65
<tag name =" kernel.event_listener" event =" kernel.request" method =" onKernelRequest" priority =" 5" />
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the API Platform project.
5
+ *
6
+ * (c) Kévin Dunglas <[email protected] >
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ declare (strict_types=1 );
13
+
14
+ namespace ApiPlatform \Core \JsonApi \EventListener ;
15
+
16
+ use Symfony \Component \HttpKernel \Event \GetResponseEvent ;
17
+ use Symfony \Component \HttpKernel \Exception \BadRequestHttpException ;
18
+
19
+ /**
20
+ * @internal
21
+ *
22
+ * @see http://jsonapi.org/format/#fetching-includes
23
+ */
24
+ final class IncludeParametersListener
25
+ {
26
+ public function onKernelRequest (GetResponseEvent $ event )
27
+ {
28
+ $ request = $ event ->getRequest ();
29
+
30
+ if (
31
+ 'jsonapi ' !== $ request ->getRequestFormat () ||
32
+ !$ request ->attributes ->get ('_api_resource_class ' ) ||
33
+ !$ request ->query ->get ('include ' )
34
+ ) {
35
+ return ;
36
+ }
37
+
38
+ throw new BadRequestHttpException ('Inclusion of related resources is not supported yet. ' );
39
+ }
40
+ }
You can’t perform that action at this time.
0 commit comments