Symfony NelmioApiDocBundle swagger-ui PHP Annotations json object with array of objects properties not showing

别等时光非礼了梦想. 提交于 2019-12-10 16:48:26

问题


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.

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

Here is the Json trying to post in body

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

Annotations below

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


回答1:


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

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

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



来源:https://stackoverflow.com/questions/45803820/symfony-nelmioapidocbundle-swagger-ui-php-annotations-json-object-with-array-of

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!