How do I include a query parameter in a POST request using NelmioApiDocBundle?

2.3k views Asked by At

I'm using (and new to) Symfony 3 and NelmioApiDocbundle. I want to handle a POST request that has optional query parameters. The url would be something like: http://example.com/api/updateusers?token=some_long_value

This is what I've tried for my annotations:

/**
 * Returns a JSON object.
 *
 * @ApiDoc(
 *  resource=true,
 *  description="Update a user's information.",
 *  requirements={
 *      {
 *          "name"="userid",
 *          "dataType"="string",
 *          "requirement"=".+",
 *          "description"="the user to update"
 *      }
 *  },
 *  parameters={
 *    {"name"="data", "dataType"="text area", "required"=true, "description"="Free form xml data."}
 *  },
 *  filters={
 *    {"name"="token", "dataType"="string", "required"=true, "description"="auth token for current user - user that you're making the request on behalf of."},
 *  },
 * )
 * @Route("api/updateusers")
 * @Method("POST")
 */

Requirements, parameters, and filters are all showing up in the POST body in the API sandbox. Is there another definition type that I can use that will show a query parameter in the API sandbox? If I bypass the sandbox and send the request directly to the server, the token shows up properly as a GET value. But I'd like to be able to use the API sandbox for testing and documentation.

2

There are 2 answers

0
Kalana Perera On

Import Class

use OpenApi\Annotations as OA;

and use like this

 * @OA\Parameter(
 *     name="per_page",
 *     in="query",
 *     description="Set the number of items per page by default 10",
 *     @OA\Schema(type="integer")
 * )
 *

If you noticed the 'IN' attribute is the parameter, you can use in=query or in=body

hope this helps.

0
Leonid koida On

Try to add this in your annotations, hope it helps you.

@QueryParam(name="<your_name>", nullable=[true|false], requirements="\d+", description="<your_decription>")