Nelmioapidocbundle: post json as body does not work

Created on 21 Aug 2017  路  9Comments  路  Source: nelmio/NelmioApiDocBundle

    /**
     * @Security("is_granted('IS_AUTHENTICATED_FULLY')")
     * 
     * @Route("/api/shipping/cart/height", name="get_shipping_cart_height", methods={"POST"})
     * @SWG\Post(
     *
     *     consumes={"application/json"},
     *     produces={"application/json"},
     *     tags={"Shipping"},
     *     type="styring",
     *     @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",
     *       defaultValue="{"postalCode":"75056","items":[{"code":"3288","quantity":"2"},{"code":"3289","quantity":"1"}]}" 
     *     ),      
     *     @SWG\Response(
     *         response=200,
     *         description="Returns total ground rate",
     *     ),
     *     @SWG\Response(
     *         response=401,
     *         description="Expired JWT Token | JWT Token not found | Invalid JWT Token",
     *     ) 
     *
     *
     * )     
     *
     */

https://stackoverflow.com/questions/45803820/symfony-nelmioapidocbundle-swagger-ui-php-annotations-cannot-post-json-body

Most helpful comment

I have got the same problem, solved removing "type=json" key from SWG\Parameter

* @SWG\Post( * security={ * {"api_key":{}} * }, * summary="Validates delivery address", * tags={"checkout"}, * consumes={"application/json"}, * produces={"application/json"}, * @SWG\Parameter( * name="body", * in="body", * description="JSON Payload", * required=true, * format="application/json", * @SWG\Schema( * type="object", * @SWG\Property(property="title", type="string", example="Mr"), * @SWG\Property(property="first_name", type="string", example="Bob"), * @SWG\Property(property="last_name", type="string", example="Jones"), * @SWG\Property(property="address1", type="string", example="1 Mayfair"), * @SWG\Property(property="address2", type="string", example="Mr"), * @SWG\Property(property="town", type="string", example="London"), * @SWG\Property(property="postcode", type="string", example="232323"), * @SWG\Property(property="country", type="string", example="FR"), * @SWG\Property(property="phone", type="string", example="34343243243"), * ) * * ), * )

All 9 comments

I updated it to

* @SWG\Parameter( * name="body", * in="body", * description="json order object", * type="json", * required=true, * paramType="body", * @SWG\Schema( * type="object", * @SWG\Items( * name="postalCode", * type="string", * default="75056", * required=true * ), * @SWG\Items( * name="code", * type="array", * default="3288", * required=true * ), * @SWG\Items( * name="quantity", * type="string", * default="2", * required=true * ), * )

now I get an empty object but my items or example values do not show

still not totally working I do not get the properties i n the array of objects

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

Hi, I have a similar issue. I can get the json to display in the docs as the example value, but when I click 'Execute' nothing happens, and no error message.

     * @SWG\Post(
     *      security={
     *          {"api_key":{}}
     *      },
     *      summary="Validates delivery address",
     *      tags={"checkout"},
     *      consumes={"application/json"},
     *      produces={"application/json"},
     *      @SWG\Parameter(
     *          name="body",
     *          in="body",
     *          description="JSON Payload",
     *          required=true,
     *          type="json",
     *          format="application/json",
     *          @SWG\Schema(
     *              type="object",
     *              @SWG\Property(property="title", type="string", example="Mr"),
     *              @SWG\Property(property="first_name", type="string", example="Bob"),
     *              @SWG\Property(property="last_name", type="string", example="Jones"),
     *              @SWG\Property(property="address1", type="string", example="1 Mayfair"),
     *              @SWG\Property(property="address2", type="string", example="Mr"),
     *              @SWG\Property(property="town", type="string", example="London"),
     *              @SWG\Property(property="postcode", type="string", example="232323"),
     *              @SWG\Property(property="country", type="string", example="FR"),
     *              @SWG\Property(property="phone", type="string", example="34343243243"),
     *          )
     *
     *      ),
     * )

I have got the same problem, solved removing "type=json" key from SWG\Parameter

* @SWG\Post( * security={ * {"api_key":{}} * }, * summary="Validates delivery address", * tags={"checkout"}, * consumes={"application/json"}, * produces={"application/json"}, * @SWG\Parameter( * name="body", * in="body", * description="JSON Payload", * required=true, * format="application/json", * @SWG\Schema( * type="object", * @SWG\Property(property="title", type="string", example="Mr"), * @SWG\Property(property="first_name", type="string", example="Bob"), * @SWG\Property(property="last_name", type="string", example="Jones"), * @SWG\Property(property="address1", type="string", example="1 Mayfair"), * @SWG\Property(property="address2", type="string", example="Mr"), * @SWG\Property(property="town", type="string", example="London"), * @SWG\Property(property="postcode", type="string", example="232323"), * @SWG\Property(property="country", type="string", example="FR"), * @SWG\Property(property="phone", type="string", example="34343243243"), * ) * * ), * )

Thanks @ibonkonesa I can confirm that when I removed "type=json" key from SWG\Parameter I can also now Try it out in the docs and Execute the example with a response. So is this a bug?

I think that the problem is not with the Bundle, because in a Symfony 4.0 project is working fine with the type key but I have had to remove it in a Symfony 4.1 project in order to get it working using the same bundle version.

Anyone got a solution? I am on Sf 4.3 + nelmio/api-doc-bundle v3.4.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BafS picture BafS  路  3Comments

knyk picture knyk  路  6Comments

NicolasGuilloux picture NicolasGuilloux  路  4Comments

manseuk picture manseuk  路  6Comments

jhkchan picture jhkchan  路  4Comments