-
-
Notifications
You must be signed in to change notification settings - Fork 900
Uupdate api-platform/core 3.2.6 error #5998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'd like to reproduce this, can you share your resources? |
Hello @soyuka, What do you mean by "Resources" ? |
the classes you have |
The error is caused by PR #5989. Previously, the method Simple example: <?php
namespace App\Command;
use App\Entity\ProductCode;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Serializer\Annotation\Groups;
class SaveProduct
{
/**
* @var Collection<int, ProductCode>
*/
#[Groups(['product:write'])]
private Collection $codes;
public function __construct()
{
$this->codes = new ArrayCollection();
}
/**
* @return Collection<int, ProductCode>
*/
public function getCodes(): Collection
{
return $this->codes;
}
public function addCode(ProductCode $code): void
{
if (!$this->codes->contains($code)) {
$this->codes->add($code);
}
}
public function removeCode(ProductCode $code): void
{
if ($this->codes->contains($code)) {
$this->codes->removeElement($code);
}
}
} <?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use App\Repository\ProductCodeRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
#[ApiResource]
#[Get]
#[ORM\Entity(repositoryClass: ProductCodeRepository::class)]
class ProductCode
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 180)]
#[Groups(['product:write'])]
private ?string $type = null;
#[ORM\Column(length: 180)]
#[Groups(['product:write'])]
private ?string $value = null;
#[ORM\ManyToOne(inversedBy: 'codes')]
#[ORM\JoinColumn(nullable: false)]
private ?Product $product = null;
public function getId(): ?int
{
return $this->id;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): void
{
$this->type = $type;
}
public function getValue(): ?string
{
return $this->value;
}
public function setValue(?string $value): void
{
$this->value = $value;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): void
{
$this->product = $product;
}
} <?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Post;
use App\Command\SaveProduct;
use App\Repository\ProductRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: ProductRepository::class)]
#[ApiResource]
#[Post(
denormalizationContext: ['groups' => ['product:write']],
input: SaveProduct::class,
)]
class Product
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
/**
* @var Collection<int, ProductCode>
*/
#[ORM\OneToMany(mappedBy: 'product', targetEntity: ProductCode::class, cascade: ['persist'], orphanRemoval: true)]
private Collection $codes;
public function __construct()
{
$this->codes = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection<int, ProductCode>
*/
public function getCodes(): Collection
{
return $this->codes;
}
public function addCode(ProductCode $code): void
{
if (!$this->codes->contains($code)) {
$this->codes->add($code);
$code->setProduct($this);
}
}
public function removeCode(ProductCode $code): void
{
if ($this->codes->removeElement($code)) {
// set the owning side to null (unless already changed)
if ($code->getProduct() === $this) {
$code->setProduct(null);
}
}
}
} |
@soyuka Your commit soyuka@85e6209 will fix this issue, but then there's still a bug: Before 3.2.6: {
"components": {
"schemas": {
"Product.SaveProduct-product.write": {
"type": "object",
"description": "",
"deprecated": false,
"properties": {
"codes": {
"type": "array",
"items": {
"$ref": "#\/components\/schemas\/ProductCode-product.write"
}
}
}
}
}
}
} After your commit: {
"components": {
"schemas": {
"Product.SaveProduct-product.write": {
"type": "object",
"description": "",
"deprecated": false,
"properties": {
"codes": {
"type": "array",
"items": {
"type": "unknown_type"
}
}
}
}
}
}
} |
Thanks this is exactly what I needed, I knew there would be some edge case with that fix, tyvm! |
You're welcome and thank you for this awesome API framework! |
Thanks @ihmels to give a basic example. Mine is very complex 😄 |
I can confirm that the |
Fixes api-platform#5998 A resource embedded in another class can be writable without having a write operation (POST, PUT, PATCH).
Fixes api-platform#5998 A resource embedded in another class can be writable without having a write operation (POST, PUT, PATCH).
Fixes api-platform#5998 A resource embedded in another class can be writable without having a write operation (POST, PUT, PATCH).
Fixes #5998 A resource embedded in another class can be writable without having a write operation (POST, PUT, PATCH).
@soyuka Late but better than never: seems to work just fine. 👍 |
Thanks @soyuka How we know when the fix will be released, maybe in the 3.2.7 ? Thanks |
API Platform version(s) affected: 3.2.6
Description
I have a project on Symfony 6.3. I updated with composer, the library "api-platform/core" from 3.2.5 to 3.2.6 and I get error "'Warning: Undefined array key '$ref'" when I try to display the page
/api
How to reproduce
Update library from 3.2.5 to 3.2.6 with composer
Possible Solution
Additional Context
Thanks guys
The text was updated successfully, but these errors were encountered: