With the following annotation:
/*
* @Swagger\Annotations\Parameter(
* name="attachments",
* in="formData",
* description="@todo: Add missing description for parameter 'attachments'",
* required=false,
* type="array",
* @Swagger\Annotations\Items(type="string", format="binary")
* )
*/
I get this notice:
@Swagger\Annotations\Items()->type="file" not allowed inside a @Swagger\Annotations\Parameter() must be "string", "number", "integer", "boolean", "array"
How could I define a parameter which accepts a collection of files?
Thank you in advance.
Uploading an arbitrary number of files (an array of files) is not supported in the spec. There is an open feature request at https://github.com/OAI/OpenAPI-Specification/issues/254. For now, you can use a binary string array as a workaround for uploading an arbitrary number of files:
3.x example:
/**
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(
* @OA\Property(
* property="filename",
* type="array",
* @OA\Items(type="string", format="binary")
* )
* )
* )
* ),
@bfanger i tried your example but i'm getting the value as a comma separated string
Same problem here, it comes as string "[object File],[object File]"
The main purpose of swagger is to document the (rest) api. Being able to test it is nice, but an optional bonus. If the person implementing the api doesn't known what to do, you can always add some extra instructions to the description field
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(
* @OA\Property(
* property="myfiles",
* type="array",
* @OA\Items(type="string", format="binary"),
* ),
* )
* )
* ),
This is how I created, but its going to the backend as string
Most helpful comment
Uploading an arbitrary number of files (an array of files) is not supported in the spec. There is an open feature request at https://github.com/OAI/OpenAPI-Specification/issues/254. For now, you can use a binary string array as a workaround for uploading an arbitrary number of files:
3.x example: