4

I have integrate swagger php api outr rest-api all service working fine but i am facing issue in post json array in api. this is not working can you please help me.

Here my swagger api code

/**
 * @SWG\Post(path="/createbetsnap/get_all_game_data",
 *   tags={"Create Betsnaps Section"},
 *   summary="This function used to get selected tournament schedule date and other master data like size, prize structure and entry fee",
 *   description="",
 *   operationId="get_all_game_data",
 *   produces={"application/json"},
 *   consumes={"application/json"},
 *   @SWG\Parameter(
 *     name="Login_Session_Key",
 *     in="header",
 *     description="The Login Session Key of logged in user.",
 *     required=true,
 *     type="string"
 *   ),
 *   @SWG\Parameter(
 *     name="game_tournament",
 *     in="formData",
 *     description="The game tournament ids array field.",
 *     required=true,
 *     type="array",
 *     @SWG\Items(type="string")
 *   ),
 *   @SWG\Response(response=200, description="success message with data array"),
 *   @SWG\Response(response=500, description="Invalid username/password supplied")
 * )
 */

above complete code on swagger which i added before my api.

I want to post game_tournament field like

{"game_tournament":["18","8"]}

But from swagger-ui panel post in below format

game_tournament=8,18

can you please help me what wrong with my code, what i need to change.

Thanks in Advance.

3 Answers 3

2

using e.g. Swagger Lume package for Laravel / Lumen, you can obtain what you are asking by:

 *     @OA\Parameter(
 *         name="game_tournament[]",
 *         in="query",
 *         description="The game tournament ids array field",
 *         required=true,
 *         @OA\Schema(type="array", @OA\Items(type="string")),
 *     ),
Sign up to request clarification or add additional context in comments.

Comments

1

To POST JSON data, you need to use an in: body parameter and specify the data type using @SWG\Schema:

 *   @SWG\Parameter(
 *     name="game_tournament",
 *     in="body",
 *     description="The game tournament ids array field.",
 *     required=true,
 *     @SWG\Schema(
 *       type="array",
 *       @SWG\Items(type="string")
 *     )
 *   ),

3 Comments

but how post array with body tag, can you please provide some example sample code. i have added in="body" but it require schema field.
@Helen Am receiving "game_tournament" field as null in my API.Girish are you able to receive the posted array in api?
I am having a almost same problem. I am trying send array in multipart formData in swagger 2.0 in laravel. But it is not working. any suggestion? the format is like settings["web_name"], settings["uploaded_file_name"].
-1

Just try it:

  *   @SWG\Parameter(
  *       name="game_tournament[]",
  *       type="array",
  *       items="string",
  *       collectionFormat="multi",
  *       required=true,
  *       in="query",
  *   ),

Comments

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.