-
-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(serializer): allow usage of genId property for collection (#5870)
Co-authored-by: Gaëtan Petit <[email protected]>
- Loading branch information
1 parent
ce0bb9e
commit c76d9b0
Showing
3 changed files
with
57 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,9 @@ | ||
Feature: Disable Id generation on anonymous resource collections | ||
|
||
@!mongodb | ||
@createSchema | ||
Scenario: Get embed collection without ids | ||
When I add "Accept" header equal to "application/ld+json" | ||
And I send a "GET" request to "/disable_id_generation_collection" | ||
Then the response status code should be 200 | ||
Then the JSON node "disableIdGenerationItems[0].@id" should not exist |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* 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\ApiProperty; | ||
use ApiPlatform\Metadata\Get; | ||
use ApiPlatform\Metadata\Operation; | ||
|
||
#[Get('disable_id_generation_collection', provider: [DisableIdGeneration::class, 'provide'])] | ||
class DisableIdGeneration | ||
{ | ||
#[ApiProperty(identifier: true)] | ||
public int $id; | ||
|
||
/** | ||
* @var array<DisableIdGenerationItem> | ||
*/ | ||
#[ApiProperty(genId: false)] | ||
public array $disableIdGenerationItems; | ||
|
||
public static function provide(Operation $operation, array $uriVariables = [], array $context = []): self | ||
{ | ||
$a = new self(); | ||
$a->disableIdGenerationItems = [new DisableIdGenerationItem('test'), new DisableIdGenerationItem('test2')]; | ||
|
||
return $a; | ||
} | ||
} | ||
|
||
class DisableIdGenerationItem | ||
{ | ||
public function __construct(public string $title) | ||
{ | ||
} | ||
} |