phpsymfonyopenapinelmioapidocbundle

Swagger annotation for query parameters


I am converting a POST request to a GET request. I am using NelmioApiDocBundle to document my API endpoints. I currently have the following (old) annotation:

/**
 * @SWG\Response(
 *     response=200,
 *     description="Success - return JSON",
 * )
 * @SWG\Tag(name="Open Vacancies")
 *
 * @SWG\Parameter(
 *     name="Message body",
 *     in="body",
 *     type="string",
 *     description="JSON string specifying a page number and page size",
 *     required=true,
 *     @SWG\Schema(
 *         type="object",
 *         @SWG\Property(property="page", type="integer"),
 *         @SWG\Property(property="pageSize", type="integer")
 *     )
 * )
 *
 * @Route("/open-vacancies", methods={"POST"}, defaults={"_format": "json"}, name="api.open_vacancies")
 */

Now I want developers to be able to call my endpoint with a url like https://myapi.myapp.com/open-vacancies?page=1&pageSize=10. But I don't know how to define the documentation in annotation form. Google hasn't helped me out much. Can someone point me toward the relevant documentation for this (or, failing that, type in an example of an annotation I could use)?


Solution

  • To document a query parameter, you can also use the @SWG\Parameter annotation, but you set the value of in to query instead of body

    Example :

    /**
     * @SWG\Parameter(
     *     name="pageSize",
     *     in="query",
     *     type="string",
     *     description="Description goes here"
     * )
     */