【问题标题】:Indexed array in query查询中的索引数组
【发布时间】:2021-05-28 15:44:12
【问题描述】:

我正在努力为必须作为整数索引数组的字段编写参数注释:

voucher_products[0]: 23
voucher_products[1]: 102
voucher_products[2]: 233

我尝试了以下

 *     @OA\Parameter(
 *         name="voucher_products",
 *         in="query",
 *         description="",
 *         required=false,
 *         @OA\Schema(
 *             type="array",
 *               @OA\Items(
 *                 type="integer",
 *               )
 *         )
 *     ),
 

我是这样填写表格的: form

我在查询字符串参数中得到的结果是

voucher_products: 23
voucher_products: 102
voucher_products: 233

如果我在 $_POST 中检查这个字段,它的最终值是voucher_products=233,因为它不会变成一个数组。

我做错了什么?

【问题讨论】:

    标签: openapi swagger-php


    【解决方案1】:

    OpenAPI 规范目前没有办法表示包含索引数组的查询字符串,例如

    ?arr[0]=val1&arr[1]=val2&arr[2]=val3&...
    

    以下是 OpenAPI 规范存储库中的相关问题:
    Are indexes in the query parameter array representable?
    Support deep objects for query parameters with deepObject style


    但是,如果您的 API 可以接受只有方括号但没有索引的数组

    ?voucher_products[]=23&voucher_products[]=102&voucher_products[]=233
    

    然后你可以用name="voucher_products[]"将它定义为一个参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-14
      • 2012-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多