无法让数组键与 Swagger 一起使用
Can't get array key to work with Swagger
/**
* @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]
此文档块呈现以下 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
的数组?
如果您不希望客户端直接在请求正文中 post 数组,但带有键,则需要将 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
*/
/**
* @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]
此文档块呈现以下 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
的数组?
如果您不希望客户端直接在请求正文中 post 数组,但带有键,则需要将 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
*/