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

What I'm trying to do is to receive an Array of numbers with the key entries.

entries: [1, 2, 3]

This docblock renders the following CURL.

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

How can I get it to send the array with the key entries?

2
  • 1) By "docblock" do you mean Swagger UI? Can you post an image? 2) Do you need to post as JSON {"entries": [1, 2, 3] } or as form data entries=1,2,3? Commented Apr 5, 2018 at 15:22
  • 1) It's the code I posted. Annotation/docblock, whatever you call it. 2) JSON Commented Apr 10, 2018 at 8:48

1 Answer 1

1

If you don't want the client to post the array directly in the request-body, but with a key, you'll need to specify the in=body parameter as type="object" and define the array as a property of that schema.

Like this:

/**
 * @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
 */
Sign up to request clarification or add additional context in comments.

3 Comments

Is there any way to initialize array as [1, 2, 3]? Right now it is [0].
property example causes error, example=[1, 2, 3]
You'll need to use doctrine's array notation {1,2,3} zircote.github.io/swagger-php/guide/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.