I am trying to test my API and I have to upload a file.
But I am not able to write proper annotation for uploading file using swagger ui..
How can I do it?
* @OA\Post(
* path="/api/v1/customer/save",
* operationId="saveNewCustomer",
* tags={"Customer"},
* summary="Create a new customer",
* description="Create a new customer",
* @OA\RequestBody(
* required=true,
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(
@OA\Property(property="documentType",description="documentType.",type="string",default="license"),
* @OA\Property(property="documentFile",description="documentType.",
* @OA\Schema(
* type="string",
* format="binary"
* )
* ),
*
* @OA\Response(response=200,description="successful operation",
* @OA\MediaType(mediaType="application/json")
* ),
* @OA\Response(response=400, description="Bad request"),
* @OA\Response(response=404, description="Resource Not Found"),
* )
Try this,
/**
* ...
* @OA\RequestBody(
* required=true,
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(
* @OA\Property(
* property="documentType",
* description="documentType",
* type="file",
* @OA\Items(type="string", format="binary")
* ),
* ),
* ),
* ),
*
* @OA\Response(response=200,description="successful operation",
* @OA\MediaType(mediaType="application/json")
* ),
* @OA\Response(response=400, description="Bad request"),
* @OA\Response(response=404, description="Resource Not Found"),
* )
* ...
*/
I am using this for regular properties + multiple file uploads in a single post.
NOTE Support for multiple file uploads in a single request is borked in swagger-ui. See https://github.com/swagger-api/swagger-ui/issues/4600
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(
* allOf={
* @OA\Schema(ref="#components/schemas/item"),
* @OA\Schema(
* @OA\Property(
* description="Item image",
* property="item_images[]",
* type="array",
* @OA\Items(type="string", format="binary")
* )
* )
* }
* )
* )
* ),
Single file upload should be:
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(
* allOf={
* @OA\Schema(ref="#components/schemas/item"),
* @OA\Schema(
* @OA\Property(
* description="Item image",
* property="item_image",
* type="string", format="binary"
* )
* )
* }
* )
* )
* ),
I'm closing this issue as it is not a bug/limitation of swagger-php.
Most helpful comment
I am using this for regular properties + multiple file uploads in a single post.
NOTE Support for multiple file uploads in a single request is borked in swagger-ui. See https://github.com/swagger-api/swagger-ui/issues/4600
Single file upload should be: