4

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

enter image description here

0

1 Answer 1

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...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.