无法使用数组键与Swagger一起使用

时间:2018-04-05 14:02:11

标签: swagger swagger-php

  /**
  * @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
  */

我尝试做的是使用密钥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发送数组?

1 个答案:

答案 0 :(得分: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
 */
相关问题