1

我正在寻找一种向通过 NelmioAPiDoc 实现的 swagger-ui 添加多种响应类型的方法

在此处输入图像描述

我想选择 image/jpeg 作为响应类型 我有代码可以在控制器中工作以将主体设置为图像即使响应类型仍然是 application/json 但我的目标是如果 'application/json' 是selected 它以 json 格式返回图像的 url,但如果选择了“image/jpeg”,它会将图像返回到正文。非常感谢任何帮助。

 /**
 * @Security("is_granted('IS_AUTHENTICATED_FULLY')")
 *
 * @Route("/api/airs/renderframe", name="get_airs_frame", methods={"GET"})
 *
 * @SWG\Response(
 *     response=200,
 *     description="Returns json image url from paramaters",
 * )
 * @SWG\Parameter(
 *     name="imageHost",
 *     in="query",
 *     type="string",
 *     description="image host"
 * )
 * @SWG\Parameter(
 *     name="imagePath",
 *     in="query",
 *     type="string",
 *     description="image path"
 * )
 *

我也尝试将它添加到我的班级顶部,但仍然有一个下拉选项

 /**
 *  @SWG\Swagger(
 *               schemes={"http"},
 *               produces={"image/jpeg","application/json"},
 *               consumes={"application/json"}
 *  )
 */
4

1 回答 1

0

通过将produces{}放在@SWG\Get() 中使其工作,但响应类型不在请求中,作为参数需要现在弄清楚如何访问该值

    /**
 * @Security("is_granted('IS_AUTHENTICATED_FULLY')")
 *
 * @Route("/api/airs/renderframe", name="get_airs_frame", methods={"GET"})
 *
 * @SWG\Get(
 *     produces={"application/xml", "application/json"},
 *     @SWG\Parameter(
 *         name="imageHost",
 *         in="query",
 *         type="string",
 *         description="image host"
 *     ),
 *     @SWG\Parameter(
 *         name="imagePath",
 *         in="query",
 *         type="string",
 *         description="image path"
 *     ),
 *     @SWG\Parameter(
 *         name="resource",
 *         in="query",
 *         type="string",
 *         default="renderframe/serveframe",
 *         description="Render picture in frame"
 *     ),
 *     @SWG\Parameter(
 *         name="maxSize",
 *         in="query",
 *         type="integer",
 *         description="image max Size"
 *     ),
 *     @SWG\Parameter(
 *         name="inchesWidth",
 *         in="query",
 *         type="integer",
 *         description="image inches WIdth"
 *     ),
 *     @SWG\Parameter(
 *         name="inchesHeight",
 *         in="query",
 *         type="integer",
 *         description="image inches Height"
 *     ),
 *     @SWG\Response(
 *         response=200,
 *         description="Returns json image url from paramaters",
 *     ),
 *     @SWG\Tag(name="Render picture in frame")
 * )
于 2017-06-20T20:55:10.127 回答