DarkaOnLine / L5-Swagger

OpenApi or Swagger integration to Laravel
https://github.com/DarkaOnLine/L5-Swagger
MIT License
2.64k stars 394 forks source link

How I can use object type when file media type exists? #542

Closed Hosseinasadian closed 8 months ago

Hosseinasadian commented 1 year ago

Description:

I use @OA\MediaType(mediaType="multipart/form-data") to upload file but in this state i can't use object type. When i get data by $request->all() objects returned as json and i must decode them. When I do this with other tools like postman it's work correctly.

My comment is below:

/**
 * @OA\Post(
 *      path="/inspector/investigation/new-report/{form}",
 *      operationId="StoreNewReportByInspector",
 *      tags={"Report"},
 *      summary="Add a new report by investigation",
 *      @OA\MediaType(mediaType="multipart/form-data"),
 *      @OA\Parameter(
 *          name="form",
 *          in="path",
 *          description="The ID of the form",
 *          required=true,
 *          example="64634e4898c4113f35067f05",
 *          @OA\Schema(
 *              type="string",
 *          ),
 *      ),
 *      @OA\RequestBody(
 *       @OA\MediaType(
 *           mediaType="multipart/form-data",
 *           @OA\Schema(
 *               type="object",
 *              @OA\Property(
 *                  property="data",
 *                  type="object",
 *                  description="Data structure related to the selected form",
 *                  example={
 *                      "646a13353cda5de8310be64b": "kjskjds",
 *                      "646b146479176e07a308fec2": {
 *                          "مشکل در نحوه اتصال"
 *                      },
 *                      "646b3c5c79176e07a308fecb": 0
 *                  }
 *              ),
 *              @OA\Property(
 *                  property="location",
 *                  type="object",
 *                  description="Location of the inspector",
 *                  example={
 *                      "lat": "45.3265478",
 *                      "lng": "46.3214587"
 *                  }
 *              ),
 *              @OA\Property(
 *                  property="noncompliance",
 *                  type="object",
 *                  description="Investigation noncompliance",
 *                  example={
 *                      "646b3c5c79176e07a308fecb": "مشکل در نحوه اتصال"
 *                  }
 *              ),
 *         @OA\Property(
 *                  property="file",
 *                  type="file"
 *               ),
 *          )
 * )
 *      ),
 *      @OA\Response(
 *          response=200,
 *          description="Successful operation",
 *          @OA\JsonContent()
 *      ),
 *      @OA\Response(
 *          response=404,
 *          description="Not Found Exception",
 *          @OA\JsonContent()
 *      ),
 *      security={{ "bearer_token": {} }}
 * )
 */

and the request all result is as following:

{ "data": "{\r\n \"646a13353cda5de8310be64b\": \"kjskjds\",\r\n \"646b146479176e07a308fec2\": [\r\n \"مشکل در نحوه اتصال\"\r\n ],\r\n \"646b3c5c79176e07a308fecb\": 0\r\n}", "location": "{\r\n \"lat\": \"45.3265478\",\r\n \"lng\": \"46.3214587\"\r\n}", "noncompliance": "{\r\n \"646b3c5c79176e07a308fecb\": \"مشکل در نحوه اتصال\"\r\n}", "file": {} }

Steps To Reproduce: