2

I want to receive in my api via $_POST (formData) an array like this:

answers[458]=hi&answers[90]=hello

.

array(1) {
  ["answer"]=>
  array(2) {
    [458]=>
    string(2) "hi"
    [90]=>
    string(5) "hello"
  }
}

When i use postman i can do this so for my code there is no problem, but now i want to use swagger and thats where i cant get it to work.

i've tried

/**
 * @SWG\Post(
 *   path="/sec/answer",
 *   summary="location",
 *   tags={"question"},
 *   @SWG\Parameter(
 *         name="answer",
 *         in="formData",
 *         description="",
 *         type="array",
 *         @SWG\Items(
 *             type="string"
 *         )
 *   ),
 *   @SWG\Response(
 *     response=200,
 *     description="array"
 *   )
 * )
 */

But the problem with this is that i get a field with multiple lines in swagger and when i fill this with: hi hello

this results in the following request:

'answer=hi&answer=hello'

with this result:

array(1) {
  ["answer"]=>
  string(5) "hello"
}

i know that with this option i cant receive an array with a variable key(because i cant fill in the key), but as far as i can see this isn't even an array swagger sends a wrong request with overruling parameters.

What to do? I hope someone can help me

Ps. i have also tried an array within an array but this has the same result

0 Answers0