如何解决我的部分 API 实体未显示在其架构中
我的 API 资源的某些部分未显示在架构部分中。
我看到了我在实体文件中创建的行,我看到了 MysqL 表中的行,但在生成的架构中。
在网上寻找更简单的问题时,我发现了序列化组,但我不相信这是解决方案。 https://api-platform.com/docs/core/subresources/#using-serialization-groups
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\ProductRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ApiResource()
* @ORM\Entity(repositoryClass=ProductRepository::class)
*/
class Product
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string",length=255)
*/
private $title;
/**
* @ORM\Column(type="string",length=255,nullable=true)
*/
private $shortDescription;
/**
* @ORM\Column(type="text",nullable=true)
*/
private $description;
/**
* @ORM\Column(type="text",nullable=true)
*/
private $content;
/**
* @ORM\Column(type="string",nullable=true)
*/
private $sku;
/**
* @ORM\Column(type="boolean")
*/
private $live;
/**
* @ORM\ManyToMany(targetEntity=Category::class,mappedBy="products")
*/
private $categories;
/**
* @ORM\OnetoMany(targetEntity=Attributes::class,mappedBy="product",orphanRemoval=true)
*/
private $attributes;
public function __construct()
{
$this->categories = new ArrayCollection();
$this->attributes = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getShortDescription(): ?string
{
return $this->shortDescription;
}
public function setShortDescription(?string $shortDescription): self
{
$this->shortDescription = $shortDescription;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(?string $content): self
{
$this->content = $content;
return $this;
}
public function getSku(): ?string
{
return $this->sku;
}
public function setSku(?string $sku): self
{
$this->sku = $sku;
return $this;
}
public function getLive(): ?bool
{
return $this->live;
}
public function setLive(bool $live): self
{
$this->live = $live;
return $this;
}
/**
* @return Collection|Category[]
*/
public function getCategories(): Collection
{
return $this->categories;
}
public function addCategory(Category $category): self
{
if (!$this->categories->contains($category)) {
$this->categories[] = $category;
$category->addProduct($this);
}
return $this;
}
public function removeCategory(Category $category): self
{
if ($this->categories->removeElement($category)) {
$category->removeProduct($this);
}
return $this;
}
/**
* @return Collection|Attributes[]
*/
public function getAttributes(): Collection
{
return $this->attributes;
}
public function addAttribute(Attributes $attribute): self
{
if (!$this->attributes->contains($attribute)) {
$this->attributes[] = $attribute;
$attribute->setProduct($this);
}
return $this;
}
public function removeAttribute(Attributes $attribute): self
{
if ($this->attributes->removeElement($attribute)) {
// set the owning side to null (unless already changed)
if ($attribute->getProduct() === $this) {
$attribute->setProduct(null);
}
}
return $this;
}
}
这是它生成的架构。
"Product": {
"type": "object","description": "","properties": {
"id": {
"readOnly": true,"type": "integer"
},"description": {
"type": "string","nullable": true
},"shortDescription": {
"type": "string","content": {
"type": "string","sku": {
"type": "string","live": {
"type": "boolean"
},"categories": {
"type": "array","items": {
"type": "string","format": "iri-reference"
}
}
}
},
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。