为什么添加自定义集合操作会删除 post 方法?

Why adding custom collection operation removes post method?

如果我只使用@ApiResource()注解结果如下:

当我尝试添加自定义操作时,缺少 post 集合操作:

 * @ApiResource(
 *     collectionOperations={"get", "find_between" = {
 *          "method"="GET",
 *          "path"="/bookings/find_between",
 *          "openapi_context" = {
 *                  "parameters" = {
 *                      {
 *                          "name" = "startAt",
 *                          "in" = "query",
 *                          "description" = "Start date & time for bookings retrieval",
 *                          "required" = "true",
 *                          "type" : "string",
 *                          "format" : "date-time"
 *                      },
 *                      {
 *                          "name" = "endAt",
 *                          "in" = "query",
 *                          "description" = "End date & time for bookings retrieval",
 *                          "required" = "true",
 *                          "type" : "string",
 *                          "format" : "date-time"
 *                      }
 *                  }
 *               }
 *          }
 *     },
 * )

因为,如 docs 中所述:

If no operation is specified, all default CRUD operations are automatically registered. It is also possible - and recommended for large projects - to define operations explicitly.

如果您明确定义操作,则只有定义的操作可用。

默认的 item 操作是:

  • 得到
  • 删除

默认的集合操作是:

  • 得到
  • post

在您的示例中,您定义了两个集合操作:getfind_between。由于 post 也是一个集合操作,通过省略它,您实际上 禁用了 该操作。

如果您要明确定义组(项目、集合)中的任何一个操作;您需要定义所有要启用的。