【问题标题】:Swagger-UI Symfony NelmioAPiDoc add multiple responseType optionsSwagger-UI Symfony NelmioAPiDoc 添加多个 responseType 选项
【发布时间】:2017-11-23 10:52:25
【问题描述】:

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

我希望图像/jpeg 选项作为响应类型我有代码在控制器中工作以将主体设置为图像即使响应类型仍然是 application/json 但我的目标是如果'application/ json' 被选中,它以 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"}
 *  )
 */

【问题讨论】:

    标签: symfony swagger-ui nelmioapidocbundle


    【解决方案1】:

    通过将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")
     * )
    

    【讨论】:

      猜你喜欢
      • 2018-06-18
      • 1970-01-01
      • 1970-01-01
      • 2020-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多