首页 > 解决方案 > 如何在 Api-Platform 上使用带有 Messanger 输入的路径中的 {id}?

问题描述

我有这样的事情:

/**
 * @ORM/Entity
 * @ApiResource(
 *     itemOperations={
 *         "put_cancel": {
 *             "method": "PUT",
 *             "path": "/task/{id}/cancel",
 *             "messenger": "input",
 *             "input": CancelTaskCommand::class,
 *             "output": false
 *         },
 *     }
 * )
 */
class Foo {}

CancelFooCommand.php

final class CancelFooCommand
{
    /**
     * @var string
     * @ApiProperty(
     *     identifier=true,
     * )
     */
    public string $id = '';

    /**
     * @var string
     * @ApiProperty(
     *     attributes={
     *         "openapi_context"={
     *           "type": "string"
     *         }
     *     }
     * )
     */
    public string $note = '';
}

所以我必须在有效载荷和路径中输入两次 id。是否可以跳过添加id到有效负载并从路径获取它?

标签: phpsymfonyapi-platform.com

解决方案


推荐阅读