0
  /**
  * @SWG\POST(
  *   path="/visa-entry/calculate",
  *   operationId="visaEntryCalculate",
  *   tags={"Visa Entry"},
  *   summary="Calculate the price for an array of visa entries",
  *   description="Calculate the price for an array of visa entries",
  *
  *   @SWG\Parameter(
  *     name="entries",
  *     in="body",
  *     description="Visa Entry IDs to calculate to total price",
  *     required=true,
  *     @SWG\Schema(
  *       type="array",
  *       @SWG\Items(type="number")
  *     ),
  *     collectionFormat="multi"
  *   ),
  *
  *   @SWG\Response(
  *     response=200,
  *     description="OK"
  *   ),
  *
  *   @SWG\Response(
  *     response=400,
  *     description="Bad request"
  *   ),
  * )
  *
  * Calculates a visa entry
  */

我想要做的是接收带有 key 的数字数组entries

entries: [1, 2, 3]

此 docblock 呈现以下 CURL。

curl -X POST "app.test/visa-entry/calculate" -H "accept: application/json" -H "Content-Type: application/json" -H "X-CSRF-TOKEN: " -d "[0]"

我怎样才能让它用密钥发送数组entries

4

1 回答 1

1

如果您不希望客户端直接在请求正文中发布数组,但使用键,则需要将in=body参数指定为type="object"并将数组定义为该模式的属性。

像这样:

/**
 * @SWG\POST(
 *   path="/visa-entry/calculate",
 *   operationId="visaEntryCalculate",
 *   tags={"Visa Entry"},
 *   summary="Calculate the price for an array of visa entries",
 *   description="Calculate the price for an array of visa entries",
 *
 *   @SWG\Parameter(
 *     in="body",
 *     name="json",
 *     description="Visa Entry IDs to calculate to total price",
 *     required=true,
 *     @SWG\Schema(
 *       type="object",
 *       @SWG\Property(
 *         property="entries",
 *         type="array",
 *         @SWG\Items(type="number")
 *       )
 *     ),
 *     collectionFormat="multi"
 *   ),
 *
 *   @SWG\Response(
 *     response=200,
 *     description="OK"
 *   ),
 *
 *   @SWG\Response(
 *     response=400,
 *     description="Bad request"
 *   ),
 * )
 *
 * Calculates a visa entry
 */
于 2018-04-12T21:48:01.387 回答