LoginSignup
1
0

More than 3 years have passed since last update.

symfonyのapi-platformでNo item route associated with the type "App\Entity\クラス名"

Posted at

はじめに

api-platformを使っていて、躓いた部分のメモです。

問題

Symfonyのapi-platformで開発をしていて、No item route associated with the type "App\Entity\クラス名"というエラーが表示された。

状況

MySQLのViewで作成したテーブルなので、ReadOnlyのつもりで、collectionOperationsのGETのみとして以下の設定を行った。

/**
 * @ApiResource(
 *     collectionOperations={
 *      "get"
 *     },
 *     itemOperations={
 *     },
 * )
 * @ORM\Entity(repositoryClass=hogehoge::class, readOnly=true)
 * @ORM\Table(name="view_hogehoge")
 */

以下の画面でも正常に表示されているので良さそうな感じ。

2020-08-13_11h55_24.png

しかし、実際にAPIを呼び出すと、エラーを吐く

2020-08-13_11h57_54.png

回答

アノテーションの以下の書き方がダメ。
Issuに上がっていた。
https://github.com/api-platform/core/issues/3501

 *     itemOperations={
 *     },

こちらのように書くと動作する

/**
 * @ApiResource(
 *     collectionOperations={
 *      "get"
 *     },
 *     itemOperations={
 *         "get"={
 *             "method"="GET",
 *             "controller"=NotFoundAction::class,
 *             "read"=false,
 *             "output"=false,
 *         },
 *     },
 * )
 * @ORM\Entity(repositoryClass=hogehoge::class, readOnly=true)
 * @ORM\Table(name="view_hogehoge")
 */

言い訳

R/Wできるテーブルで使っているので、R/Oの場合にちょこっと書き方を変えたら躓いてしまった。

しかも、利用者が少ないのか、日本語での回答がなかったので書いてみました。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0