Skip to content
Advertisement

Entity not visible in swagger UI api platform

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 AppEntity;

use ApiPlatformCoreAnnotationApiResource;

/** 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;
    }
}

Advertisement

Answer

I think you should delete your Entity and remake it with the cmd :

php bin/console make:entity

that will make a Rewiew.php files in Entity folders with getter and setter and correct annotations examples :

 /**
 * @ORMColumn(type="string", length=100, nullable=true)
 */

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

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement