Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File upload input not shown with swagger ui using swagger-php with OA #666

Closed
birendragurung opened this issue Apr 8, 2019 · 3 comments
Closed

Comments

@birendragurung
Copy link

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"),
	 *  )
@birendragurung birendragurung changed the title File is not uploaded with swagger ui using swagger-php with OA File upload input not shown with swagger ui using swagger-php with OA Apr 8, 2019
@ottaz
Copy link

ottaz commented Jun 13, 2019

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"),
*  )

* ...
*/

@DerManoMann
Copy link
Collaborator

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 swagger-api/swagger-ui#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"
     *                         )
     *                     )
     *                 }
     *             )
     *         )
     *     ),

@bfanger
Copy link
Collaborator

bfanger commented Jul 6, 2019

I'm closing this issue as it is not a bug/limitation of swagger-php.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants