4

我正在尝试使用 NelmioApiDocBundle 发布 json,我显示了 json 示例,但尝试示例中没有显示数组对象属性?我尝试了几种方法来完成此操作,但均未成功,以下是我尝试过的代码。非常感谢任何帮助。

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

这是试图在正文中发布的 Json

      '{
          "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",
 *     ) 
 *
 *
 * )     
 *
 */

在此处输入图像描述

4

1 回答 1

1
    /**
     * @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年内找到了解决方案:)
但我很乐意在这个答案中更快地找到这个解决方案......

于 2019-09-04T08:08:55.537 回答