How to add JSON request and response examples in Swagger (OpenApi)?
For NelmioApiDocBundle v4 you can do like this
use OpenApi\Annotations as OA;/** * @OA\Parameter( * name="body", * in="path", * required=true, * @OA\JsonContent( * type="object", * @OA\Property(property="property1", type="number"), * @OA\Property(property="property2", type="number"), * ), * ) * * @OA\Response( * response=200, * description="", * @OA\JsonContent( * type="object", * @OA\Property(property="property1", type="number"), * @OA\Property(property="property2", type="number"), * ) * ) */
For v3
use Swagger\Annotations as SWG;/** * @SWG\Parameter( * name="body", * in="body", * required=true, * @SWG\Schema( * @SWG\Property(property="test1", type="string"), * @SWG\Property(property="test2", type="string"), * ), * ) * * @SWG\Response( * description="", * response=200, * @SWG\Schema( * @SWG\Property(property="test1", type="string"), * @SWG\Property(property="test2", type="string"), * ), * ) */
But better to do it via @Model annotation, as described in the doc if you have DTO or entity.