Search code examples
laravelswaggerlaravel-api

How to operate the GET method with parameters in Swagger?


I'm using Swagger to do the documentation of the Laravel API's, and sometimes there is also testing apart from POSTMAN, the issue is that the GET methods with parameters do not work Route::get('/searchProduct/{id}','Api\ReportController@getProductsByID');

But if the GET method does not have parameters it works perfectly. In Swagger I realized that when I make the query I don't enter the parameter in {id} but I believe after {id}?id=4

This is my route

My route
Route::get('/searchProduct/{id}','Api\ReportController@getProductsByID');

Result in Swagger
www.x.cl/api/searchProduct/{id}?id=4 //ERROR

How it should work
www.x.cl/api/searchProduct/4 

Because in POSTMAN I only change my ID by the number and the search works for me.

This is my controller

    /**
     *  @OA\Get(
     *      path="/api/searchProduct/{id}",
     *      summary="Search Product by Status",
     *      description="Lorem ipsun",
     *      security={
     *          {"bearer_token":{}},
     *      },
     *      @OA\Parameter(
     *         name="id",
     *         in="query",
     *         description="Buscar por estado",
     *         required=true,
     *      ),
     *      @OA\Response(
     *          response=200,
     *          description="OK",
     *          @OA\MediaType(
     *              mediaType="application/json",
     *          )
     *      ),
     *      @OA\Response(
     *          response="default",
     *          description="Ha ocurrido un error."
     *      ),
     *      @OA\Response(
     *          response="401",
     *          description="No se ha autenticado, ingrese el token."
     *      ),
     *  )
     */
    public function getProductsByID($uuid){
        $validated = Product::status($uuid);
        return ReportResource::collection($validated);
    }

Solution

  • Try replacing in="query", with in="path", here :

         *      @OA\Parameter(
         *         name="id",
         *         in="query",
         *         description="Buscar por estado",
         *         required=true,
         *      ),
    

    Query refers to "query string", the set of ampersand-separated key/value pairs that come after ? in the URL.