Symfony:在nelmio api docs中输出示例图像?



我正在使用Nelmio Api Doc为我的API生成文档。我刚刚添加了一个新的端点,它根据id参数返回图像/png文件。如何在 api 文档中最好地表示此响应?理想情况下,我想在此端点文档的示例响应部分中显示示例图像。但是我可以用nelmio做到这一点吗?请看下面:

/**
*
* ### Example Response ###
*     [
*         {TELL NELIMO TO OUTPUT EXAMPLE IMAGE?}
*     ]
*
* @Route("/image/{id}", name="image_get", requirements={"id": "d+"})
* @Method("GET")
*
* @ApiDoc(
*  section="image",
*  description="Fetch image.",
*  headers={
*     {
*          "name" : "api-key",
*          "description"="Token the client needs to provide when making API calls.",
*          "required"="true"
*     }
*  },
*  requirements={
*      {
*          "name"="id",
*          "dataType"="integer",
*          "requirement"="d+",
*          "description"="ID of the image you wish to retrieve."
*      }
*  },
*  parameters={},
*  filters={},
*  statusCodes={
*      200="Returned when successful",
*      400={
*        "Returned when bad request",
*      },
*      401={
*        "Returned when unauthorized",
*      },
*      404={
*        "Returned when not found",
*      }
*   }
* )
*/
public function getAction($id, Request $request)
{
/** @var ImageRepository $imageRepository */
$imageRepository = $this->get('api.repository.image');
/** @var Image $image */
$image = $imageRepository->fetchById($id);
if(empty($image->getId())){
$problem = new ApiProblem("Image not found", "E_NOT_FOUND");
$problem->setDetail("A image could not be found.");
$problem->setInstance($request->getUri());
return new Response($problem->asJson(), Response::HTTP_NOT_FOUND);
}
/** @var string $file */
$file = file_get_contents(__DIR__ . '/../../../../app/Resources/img/' . $flag->getImg());
return new Response($file, 200, [
'Content-Type' => 'image/png',
'Content-Disposition' => 'inline; filename="'.$image->getImg().'"'
]);
}

在注释中使用 markdown,就像这样![alt text](https://some_image.png)这样,它会在 nelmio api 文档中输出它。

最新更新