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 ?

2 Answers 2

1

This is solution:

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

:)

Sign up to request clarification or add additional context in comments.

Comments

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

2 Comments

In January I found answer by myself. Do you find alternative answer? If yes - describe it here
I need a solution for using @OA (Open API Annotations).. It keep saying "Unexpected fields "consumes".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.