-
-
Notifications
You must be signed in to change notification settings - Fork 868
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(serializer): read groups off the root operation (#5196)
* fix(serializer): read groups off the root operation
- Loading branch information
Showing
6 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@php8 | ||
@!mongodb | ||
Feature: Groups to embed relations | ||
In order to show embed relations on a Resource | ||
As a client software developer | ||
I need to set up groups on the Resource embed properties | ||
|
||
Scenario: Get a single resource | ||
When I send a "GET" request to "/relation_group_impact_on_collections/1" | ||
Then the response status code should be 200 | ||
And the response should be in JSON | ||
And the JSON node "related.title" should be equal to "foo" | ||
|
||
Scenario: Get a collection resource not impacted by groups | ||
When I send a "GET" request to "/relation_group_impact_on_collections" | ||
Then the response status code should be 200 | ||
And the response should be in JSON | ||
And the JSON node "hydra:member[0].related" should be equal to "/relation_group_impact_on_collection_relations/1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
tests/Fixtures/TestBundle/Entity/RelationGroupImpactOnCollection.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity; | ||
|
||
use ApiPlatform\Metadata\ApiResource; | ||
use ApiPlatform\Metadata\CollectionOperationInterface; | ||
use ApiPlatform\Metadata\Get; | ||
use ApiPlatform\Metadata\GetCollection; | ||
use ApiPlatform\Metadata\Operation; | ||
use Symfony\Component\Serializer\Annotation\Groups; | ||
|
||
#[ApiResource( | ||
provider: [RelationGroupImpactOnCollection::class, 'getData'] | ||
)] | ||
#[GetCollection] | ||
#[Get(normalizationContext: ['groups' => 'related'])] | ||
class RelationGroupImpactOnCollection | ||
{ | ||
public ?int $id; | ||
#[Groups('related')] | ||
public ?RelationGroupImpactOnCollectionRelation $related; | ||
|
||
public function __construct($id = null, $related = null) | ||
{ | ||
$this->id = $id; | ||
$this->related = $related; | ||
} | ||
|
||
public static function getData(Operation $operation, array $uriVariables = [], array $context = []): self|array | ||
{ | ||
$item = new self($uriVariables['id'] ?? 1, new RelationGroupImpactOnCollectionRelation(id: $uriVariables['id'] ?? 1, title: 'foo')); | ||
if ($operation instanceof CollectionOperationInterface) { | ||
return [$item]; | ||
} | ||
|
||
return $item; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/Fixtures/TestBundle/Entity/RelationGroupImpactOnCollectionRelation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity; | ||
|
||
use ApiPlatform\Metadata\ApiResource; | ||
use Symfony\Component\Serializer\Annotation\Groups; | ||
|
||
#[ApiResource] | ||
class RelationGroupImpactOnCollectionRelation | ||
{ | ||
public ?int $id; | ||
|
||
#[Groups('related')] | ||
public ?string $title; | ||
|
||
public function __construct($id, $title) | ||
{ | ||
$this->id = $id; | ||
$this->title = $title; | ||
} | ||
} |