forked from api-platform/core
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jsonschema): allow embed resources
- Loading branch information
Showing
8 changed files
with
225 additions
and
15 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?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\Issue5793; | ||
|
||
use ApiPlatform\Metadata\ApiResource; | ||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Symfony\Component\Serializer\Annotation\Groups; | ||
|
||
#[ORM\Entity] | ||
#[ApiResource( | ||
normalizationContext: ['groups' => ['read']], | ||
denormalizationContext: ['groups' => ['write']], | ||
)] | ||
class BagOfTests | ||
{ | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue] | ||
#[ORM\Column] | ||
#[Groups(['read', 'write'])] | ||
private ?int $id = null; | ||
|
||
#[ORM\Column(length: 255)] | ||
#[Groups(['read', 'write'])] | ||
private ?string $description = null; | ||
|
||
#[ORM\OneToMany(mappedBy: 'bagOfTests', targetEntity: TestEntity::class)] | ||
#[Groups(['read', 'write'])] | ||
private Collection $tests; | ||
|
||
public function __construct() | ||
{ | ||
$this->tests = new ArrayCollection(); | ||
} | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getDescription(): ?string | ||
{ | ||
return $this->description; | ||
} | ||
|
||
public function setDescription(string $description): static | ||
{ | ||
$this->description = $description; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return Collection<int, TestEntity> | ||
*/ | ||
public function getTests(): Collection | ||
{ | ||
return $this->tests; | ||
} | ||
|
||
public function addTest(TestEntity $test): static | ||
{ | ||
if (!$this->tests->contains($test)) { | ||
$this->tests->add($test); | ||
$test->setBagOfTests($this); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function removeTest(TestEntity $test): static | ||
{ | ||
if ($this->tests->removeElement($test)) { | ||
// set the owning side to null (unless already changed) | ||
if ($test->getBagOfTests() === $this) { | ||
$test->setBagOfTests(null); | ||
} | ||
} | ||
|
||
return $this; | ||
} | ||
} |
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,81 @@ | ||
<?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\Issue5793; | ||
|
||
use ApiPlatform\Metadata\ApiResource; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Symfony\Component\Serializer\Annotation\Groups; | ||
|
||
#[ORM\Entity] | ||
#[ApiResource] | ||
class TestEntity | ||
{ | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue] | ||
#[ORM\Column] | ||
#[Groups(['read', 'write'])] | ||
private ?int $id = null; | ||
|
||
#[ORM\Column(length: 255, nullable: true)] | ||
#[Groups(['read', 'write'])] | ||
private ?string $nullableString = null; | ||
|
||
#[ORM\Column(nullable: true)] | ||
#[Groups(['read', 'write'])] | ||
private ?int $nullableInt = null; | ||
|
||
#[ORM\ManyToOne(inversedBy: 'tests')] | ||
private ?BagOfTests $bagOfTests = null; | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getNullableString(): ?string | ||
{ | ||
return $this->nullableString; | ||
} | ||
|
||
public function setNullableString(?string $nullableString): static | ||
{ | ||
$this->nullableString = $nullableString; | ||
|
||
return $this; | ||
} | ||
|
||
public function getNullableInt(): ?int | ||
{ | ||
return $this->nullableInt; | ||
} | ||
|
||
public function setNullableInt(?int $nullableInt): static | ||
{ | ||
$this->nullableInt = $nullableInt; | ||
|
||
return $this; | ||
} | ||
|
||
public function getBagOfTests(): ?BagOfTests | ||
{ | ||
return $this->bagOfTests; | ||
} | ||
|
||
public function setBagOfTests(?BagOfTests $bagOfTests): static | ||
{ | ||
$this->bagOfTests = $bagOfTests; | ||
|
||
return $this; | ||
} | ||
} |
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