3

I use lib: darkaonline/l5-swagger (^5.5) (which contains swagger-php + swagger-ui), I need to change header Content-Type in my POST request to upload file (to read it in Laravel Input::file('photo') ). I read that I should add consumes and produces parameters to my swagger - this is what i have:

/**
 *
 * Create Building Photo
 *
 * @SWG\Post(
 *     path="/api/v1/buildings/{buildingId}/photo",
 *     security={{"oauth2": {"*"}}},
 *     tags={"building"},
 *     consumes={"text/plain", "application/json"},
 *     produces={"text/plain", "application/json"},
 *     description="Update building",
 *     @SWG\Parameter(
 *         name="buildingId",
 *         in="path",
 *         description="Building id",
 *         required=true,
 *         type="number",
 *     ),
 *     @SWG\Parameter(
 *          name="photo",
 *          in="formData",
 *          required=true,
 *          description="Building photo",
 *          type="file",
 *     ),
 *     @SWG\Response( response=200, description="ok"),
 *     @SWG\Response( response=404, description="Building not found"),
 * )
 *
 */

But in request Content-type and Accept I always get application/json and laravel is unable to read uploaded file (when I generate request using swagger-ui). How I should change above swagger to to allow laravel read Input::file('photo') form POST request generated by swagger-ui ?

Kamil Kiełczewski
  • 85,173
  • 29
  • 368
  • 345

2 Answers2

1

This is solution:

 *     consumes={"multipart/form-data"},
 *     produces={"text/plain, application/json"},

:)

Kamil Kiełczewski
  • 85,173
  • 29
  • 368
  • 345
0

Please find solution here.

You should follow this guidelines to setup Swagger in Laravel with Passport authentication and much more

https://github.com/DarkaOnLine/L5-Swagger

Here, some listed issues that you may face during implementation.

https://github.com/DarkaOnLine/L5-Swagger/issues/57

Mayank Majithia
  • 1,916
  • 16
  • 21