2

i'm tring to make a swagger call in post using DarkaOnLine / L5-Swagger. This is the code in my controller:

/**
 * @OA\Post(
 *     path="/api/send",
 *     summary="Use to sign",
 *     description="Use send a contract to sign with eSign",
 *     operationId="MpProjects.active",
 *     tags={"Projects"},
 *     security={{"passport":{}}},
 * 
 *     @OA\RequestBody(
 *         @OA\MediaType(
 *             mediaType="raw",
 *             @OA\Schema(
 *                 type="object",
 * 
 *                 @OA\Property(
 *                     property="Name",
 *                     description="Contract name",
 *                     example="Prova Contratto",
 *                     type="string"
 *                 ),
 *                 @OA\Property(
 *                     property="EmailSubject",
 *                     description="EmailSubject",
 *                     example="Firma contratto di prova",
 *                     type="string"
 *                 ),
 *                 @OA\Property(
 *                     property="RecipientEmail",
 *                     description="RecipientEmail",
 *                     example="email@gmail.com",
 *                     type="string"
 *                 ),
 *                 @OA\Property(
 *                     property="FirstName",
 *                     description="FirstName",
 *                     example="Gabriele",
 *                     type="string"
 *                 ),
 *                 @OA\Property(
 *                     property="LastName",
 *                     description="LastName",
 *                     example="Alessi",
 *                     type="string"
 *                 ),
 *                 @OA\Property(
 *                     property="PhoneMobile",
 *                     description="PhoneMobile",
 *                     example="+393333333333",
 *                     type="string"
 *                 ),
 *                 @OA\Property(
 *                     property="Pdf",
 *                     description="Pdf",
 *                     example="base64PDF",
 *                     type="string"
 *                 )
 *             )
 *          )
 *     ),
 *     @OA\Response(
 *         response=200,
 *         description="Operation successful",
 *         @OA\MediaType(
 *             mediaType="application/json"
 *         )
 *     ),
 *
 *     @OA\Response(
 *         response=204,
 *         description="Empty response",
 *         @OA\MediaType(
 *             mediaType="application/json"
 *         )
 *     )
 * )
 */
  public function sendDoc(Request $request){
    return $request;
 }

this is how the body appears on /documentation: enter image description here But it returns an empty array with this response header: enter image description here

I think the problem is in the Curl, but i can't understand where exactly. is the request body made in right way? I tried the same call with postaman, with the same json as body, and it works...

I just need to see if the body is arriving in the controller and how it is made so i can work on it.

  • I am not sure how to work laravel and swagger, time ago I implemented swagger with symfony. Anyway, I think that you need to read the request body and return a response object. https://stackoverflow.com/a/28587288/2209876 – Maxi Schvindt Dec 28 '21 at 12:47
  • You are probably right, but the problem here is the request looks empty, so i can't return a response of it. – Gabriele Alessi Dec 28 '21 at 15:15

1 Answers1

2

Sorted. i just need to change

mediaType="raw",

into

mediaType="application/json",

even if on postman it is raw