实体在 swagger UI api 平台中不可见
我使用API平台& Symfony(5.4) + PHP 7.2.5
我自己创建了一个实体,我只是在 /src /entity中添加了一个文件,但它不起作用。
我刷新,我清除了缓存,我添加了@apiresource ...但是该实体在API平台的DOC页面上不可见。
您知道错误在哪里吗? 谢谢 !
这是我用于新实体的代码:
// 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;
}
}
I use Api Platform & Symfony (5.4) + php 7.2.5
I created an Entity by myself, I just added one file in /src/Entity and it's not working.
I refresh, I cleared cache, I adde @ApiResource... But the Entity is not visible in the doc page in API Platform.
Have you an idea where the error is ?
Thanks !
Here is the code I used for the new entity :
// 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;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用此
使用此
try replacing this
use ApiPlatform\Core\Annotation\ApiResource;
with this
use ApiPlatform\Metadata\ApiResource;
我认为您应该删除您的实体,并用CMD重新对其进行重新重新:
它将在Entity文件夹中使用Getter和setter和正确的注释示例在实体文件夹中制作一个rewiew.php文件:
以及存储库文件等。
不要忘记使用:
php bin/console make:迁移
和:
php bin/console学说:迁移:迁移
以更新数据库。而且不要忘记使用Apiplatform注释。
我认为实际上该捆绑包由于丢失的信息而不知道如何使用您的实体
I think you should delete your Entity and remake it with the cmd :
that will make a Rewiew.php files in Entity folders with getter and setter and correct annotations examples :
and repository file etc..
dont forget use :
php bin/console make:migration
and:
php bin/console doctrine:migrations:migrate
for update your database. And dont forget to use apiplatform annotation.
I think actually the bundle can't know how use your entity because of missing information