php - Symfony NelmioApiDocBundle swagger-ui PHP 注释 json 对象,对象属性数组未显示

标签 php symfony swagger-ui nelmioapidocbundle

我正在尝试使用 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",
 *     ) 
 *
 *
 * )     
 *
 */

enter image description here

最佳答案

    /**
     * @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

附言
我想你已经在 2 年内找到了解决方案 :)
但我很乐意在这个答案中更快地找到这个解决方案......

关于php - Symfony NelmioApiDocBundle swagger-ui PHP 注释 json 对象,对象属性数组未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45803820/

相关文章:

php - mysql - 已超出 'max_user_connections' 资源

php - 创建用户后无法生成 "page_slug"的 URL

php - Symfony2 ESI : Responses marked as public, 即使子请求包含私有(private)响应

java - Swagger UI 和 Play 路由 *path

.net - API 获取和浏览器崩溃后 Swagger UI 卡住

php - php mysql 对两列进行排序

php - PHP 和 MySQL 的初学者问题

php - 登录后立即显示在线用户

PHP内置服务器认为端口不可用,但netstat不同意

servicestack - Swagger (ServiceStack) 中未准确记录通用类型的响应对象