简体   繁体   中英

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)?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM