5

I want to send array by POST method to my API.

This is my code:

 /**
 * @OA\Post(path="/test/bulk/{edition}/{company}", tags={"Test"}, summary="Test",
 *     @OA\Parameter(
 *          name="company", required=true, in="path", @OA\Schema(type="integer")
 *     ),
 *     @OA\Parameter(
 *          name="edition", required=true, in="path", @OA\Schema(type="integer")
 *     ),
 *     @OA\RequestBody(
 *          @OA\MediaType(mediaType="multipart/form-data",
 *              @OA\Schema(
 *                  @OA\Property(property="key[]", type="array", collectionFormat="multi", @OA\Items(type="string")),
 *                  @OA\Property(property="value[]", type="array", collectionFormat="multi", @OA\Items(type="string")),
 *                  @OA\Property(property="file[]", type="array", collectionFormat="multi", @OA\Items(type="string", format="binary")),
 *                  @OA\Property(property="confirmed[]", type="array", collectionFormat="multi", @OA\Items(type="integer")),
 *                  required={"key", "confirmed"}
 *             )
 *         )
 *      ),
 *     @OA\Response(response=201, description="OK"),
 *     @OA\Response(response=400, description="Not Found or Validation Error"),
 * )
 */

But I don't know why swagger sends this in this way:

key[]: key1,key2,
value[]: value1,value2
file[]: 
confirmed[]: 1,0

So, how should I describe that?

curveball
  • 4,320
  • 15
  • 39
  • 49
John
  • 61
  • 2
  • 7
  • Could you add an example of how the raw request body is supposed to look like? Or the corresponding curl command? – Helen Oct 15 '18 at 19:27
  • @Helen, hmm, normal html form array (eg. https://stackoverflow.com/questions/1010941/html-input-arrays), key[] -> key 0, key[] -> key 1 – John Oct 15 '18 at 20:20
  • OpenAPI Specification does not currently provide a way to describe exploded arrays (key[] -> key 0, key[] -> key 1) in `multipart/form-data` requests. I'd suggest opening an issue in the [OpenAPI Specification repository](https://github.com/OAI/OpenAPI-Specification/issues) to clarify the array serialization rules for multipart requests. – Helen Oct 15 '18 at 21:23

0 Answers0