Symfony NelmioApiDocBundle swagger-ui PHP Annotations带有对象数组属性的JSON对象未显示 [英] Symfony NelmioApiDocBundle swagger-ui PHP Annotations json object with array of objects properties not showing

查看:175
本文介绍了Symfony NelmioApiDocBundle swagger-ui PHP Annotations带有对象数组属性的JSON对象未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用NelmioApiDocBundle发布json,我有显示json的示例,但在try it out的示例中未显示数组对象的属性?我尝试了几种方法来完成此任务,但没有成功,下面是我尝试过的代码.任何帮助,不胜感激.

I'm trying to post json with NelmioApiDocBundle, I have the json example showing up but the array object properties are not showing in the try it out example? I have tried several methods to accomplish this without success, Below is the code I have tried. Any help greatly appreciated.

当我尝试为该项目添加示例时,它会在数组周围加上引号,因此它不是有效的json,并且我必须转义引号,因此不会在我想要的地方加上斜杠

when I try to add the example for the items it puts quotes around the array so its not valid json and I have to escape the quotes so it adds slashes not what I want

这是杰森(Json)试图在体内张贴

Here is the Json trying to post in body

      '{
          "postalCode": "75056",
          "items":[
                    {
                    "code":"3288",
                    "quantity":"2"
                    },
                    {   
                    "code":"3289",
                    "quantity":"1"
                    }                           
                  ]
        }'

下面的注释

    /**
 * @Security("is_granted('IS_AUTHENTICATED_FULLY')")
 * 
 * @Route("/api/shipping/cart/length", name="get_shipping_cart_length", methods={"POST"})
 * @SWG\Post(
 *
 *     consumes={"application/json"},
 *     produces={"application/json"},
 *     tags={"Shipping"},
 *     @SWG\Parameter(
 *         name="Authorization",
 *         in="header",
 *         required=true,
 *         type="string",
 *         default="Bearer TOKEN",
 *         description="Authorization"
 *     ),    
 *     @SWG\Parameter(
 *       name="body",
 *       in="body",
 *       description="json order object",
 *       type="json",
 *       required=true,
 *       paramType="body",
 *      @SWG\Schema(
 *        type="object",   
 *        @SWG\Property(
 *             type="string",   
 *             property="postalCode",
 *             type="string",
 *             example="75056",
 *             required=true          
 *           ),
 *              @SWG\Property(
 *                  property="items",
 *                  type="array",
 *                  required=true,
 *                  @SWG\Items(
 *                      type="object",
 *                      @SWG\Property(property="code", type="string",required=true ),
 *                      @SWG\Property(property="quantity", type="string",required=true),
 *                  ),
 *              ),      
 *      )
 *     ),       
 *     @SWG\Response(
 *         response=200,
 *         description="Returns total ground rate",
 *     ),
 *     @SWG\Response(
 *         response=401,
 *         description="Expired JWT Token | JWT Token not found | Invalid JWT Token",
 *     ) 
 *
 *
 * )     
 *
 */

推荐答案

    /**
     * @SWG\Response(
     *     response=200,
     *     description="Description",
     *     examples={
     *         "application/json": {
     *              "postalCode": "75056",
     *              "items": {
     *                  {
     *                      "code":"3288",
     *                      "quantity":"2"
     *                  },
     *                  {
     *                      "code":"3289",
     *                      "quantity":"1"
     *                  }
     *              }
     *         }
     *     }
     * )
     */

来源: https://github.com/zircote/swagger -php/issues/238#issuecomment-135658716

PS
我认为您已经在2年内找到了解决方案:)
但我很乐意在此答案中更快地找到此解决方案...

PS
I think you have found a solution in 2 years :)
but I would be happy to find this solution faster in this answer...

这篇关于Symfony NelmioApiDocBundle swagger-ui PHP Annotations带有对象数组属性的JSON对象未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆