Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony:在nelmio api文档中输出示例图像?_Php_Symfony_Swagger_Nelmioapidocbundle - Fatal编程技术网

Php Symfony:在nelmio api文档中输出示例图像?

Php Symfony:在nelmio api文档中输出示例图像?,php,symfony,swagger,nelmioapidocbundle,Php,Symfony,Swagger,Nelmioapidocbundle,我正在使用为我的API生成文档。我刚刚添加了一个新的端点,它根据id参数返回image/png文件。如何在api文档中最好地表示此响应?理想情况下,我希望在此端点文档的示例响应部分显示一个示例图像。但我能和内尔米奥一起做吗?请参阅下文: /** * * ### Example Response ### * [ * {TELL NELIMO TO OUTPUT EXAMPLE IMAGE?} * ] * * @Route("/image/{id}",

我正在使用为我的API生成文档。我刚刚添加了一个新的端点,它根据id参数返回image/png文件。如何在api文档中最好地表示此响应?理想情况下,我希望在此端点文档的示例响应部分显示一个示例图像。但我能和内尔米奥一起做吗?请参阅下文:

/**
 *
 * ### 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().'"'
    ]);
}

在注释中使用标记,如so
![替换文本](https://some_image.png)
将在nelmio api文档中输出。

Markdown dude…感谢@mike完成了这项工作!普通HTML也可以做到这一点