Search code examples
annotationsswaggerswagger-php

Swagger Documentation - How can i get only values separated by a comma in the json request body?


In my case, for a DELETE operation, i will have to pass a body which looks like below.

Request body should look like:

[
 "Vi####1",
 "Vi####2"
]

But when i tried to achieve this, i always get the data type along with the value as shown below.

Request body that's getting created currently:

{
 "Vi####1": "string",
 "Vi####2": "string"
}

please find below the json creation.

class VirtualViewColDeleteReq
{

/**
 * @OA\Property(
 *     title="View ID",
 *     description="Segment Name",
 *     property="Vi####001"
 * )
 *
 * @var string
 */

/**
 * @OA\Property(
 *     title="View ID1",
 *     description="Segment Name",
 *     property="Vi####002"
 * )
 *
 * @var string
 */

}

swagger.php

 *     @OA\RequestBody(
 *          required=true,
 *          @OA\JsonContent(ref="#/components/schemas/VirtualViewColDeleteReq")
 *      ),

Any help is really appreciated.

Thanks in advance


Solution

  • You're current setup describes an object, but look like you want a simple array with strings

     *     @OA\RequestBody(
     *       required=true,
     *       @OA\JsonContent(
     *         type="array", 
     *         @OA\Items(type="string"),
     *       )
     *     )
    

    For additional clarity you can provide a format @OA\Items(type="string", format="id"), this is ignored by the tooling but gives a hint to the reader of the documentation.