实体在 swagger UI api 平台中不可见

Nei*_*luj 1 php entity symfony api-platform.com

我使用 Api 平台 & Symfony (5.4) + php 7.2.5

我自己创建了一个实体,我只是在 /src/Entity 中添加了一个文件,但它不起作用。

我刷新,清除缓存,添加@ApiResource...但是实体在API平台的文档页面中不可见。

你知道错误出在哪里吗?谢谢 !

这是我用于新实体的代码:

// api/src/Entity/Review.php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;

/** A review of a book. */
/** 
* @ApiResource()
*/
class Review
{
    /** The id of this review. */
    private ?int $id = null;

    /** The rating of this review (between 0 and 5). */
    public int $rating = 0;

    /** The body of the review. */
    public string $body = '';

    /** The author of the review. */
    public string $author = '';

    /** The date of publication of this review.*/
    public ?\DateTimeInterface $publicationDate = null;

    /** The book this review is about. */
    public ?Book $book = null;

    public function getId(): ?int
    {
        return $this->id;
    }
}
Run Code Online (Sandbox Code Playgroud)

小智 5

尝试替换这个

  • use ApiPlatform\Core\Annotation\ApiResource;

有了这个

  • use ApiPlatform\Metadata\ApiResource;