Laravel 大摇大摆的数组验证

Laravel array validation in swagger

我的表单数据由一个数组 'items' 组成,其中包含如下详细信息:

items[0][id]:1
items[0][amount]:50
items[1][id]:2
items[1][amount]:25

这是邮递员中的样子。 我怎样才能为这个结构写出夸张的评论? 下面是我创建的评论,但它不起作用。

 /**
 *  @QA\Property(
 *      property="items[]", 
 *      type="array",
 *      @QA\Items(
 *          type="object",
 *          @QA\Property(property="id", type="string"),
 *          @QA\Property(property="amount", type="string"),
 *      ),
 *  ),
 */
 public $items;

让我知道需要做什么来解决这个问题。

OpenAPI 规范目前不支持对表单数据中的嵌套对象和对象数组进行这种序列化。换句话说,没有定义这种数据格式的语法。

有相应的增强请求:
https://github.com/OAI/OpenAPI-Specification/issues/1706
它讨论了查询参数,但如果实现它也会扩展到表单数据(因为表单数据使用与查询参数相同的序列化方法)。


一种可能的解决方法是更改​​ API 以接受 application/json 而不是表单数据,并将此正文作为 JSON 对象数组发送。

"items: [
  {
    "id": 1,
    "amount": 50
  },
  {
    "id": 2,
    "amount": 25
  }
]