如何在Swagger中操作带参数的GET方法?
How to operate the GET method with parameters in Swagger?
我正在使用 Swagger 来做 Laravel API 的文档,有时除了 POSTMAN 之外还有测试,问题是带参数的 GET 方法不工作 Route::get('/searchProduct/{id}','Api\ReportController@getProductsByID');
但是如果 GET 方法没有参数,它就可以正常工作。在 Swagger 中,我意识到当我进行查询时,我没有在 {id}
中输入参数,但我相信在 {id}?id=4
之后
这是我的路线
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
因为在 POSTMAN 中我只通过数字更改我的 ID,搜索对我有效。
这是我的控制器
/**
* @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);
}
尝试在此处将 in="query",
替换为 in="path",
:
* @OA\Parameter(
* name="id",
* in="query",
* description="Buscar por estado",
* required=true,
* ),
查询指“查询字符串”,URL.
中?
之后的ampersand-separatedkey/value对集合
我正在使用 Swagger 来做 Laravel API 的文档,有时除了 POSTMAN 之外还有测试,问题是带参数的 GET 方法不工作 Route::get('/searchProduct/{id}','Api\ReportController@getProductsByID');
但是如果 GET 方法没有参数,它就可以正常工作。在 Swagger 中,我意识到当我进行查询时,我没有在 {id}
中输入参数,但我相信在 {id}?id=4
这是我的路线
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
因为在 POSTMAN 中我只通过数字更改我的 ID,搜索对我有效。
这是我的控制器
/**
* @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);
}
尝试在此处将 in="query",
替换为 in="path",
:
* @OA\Parameter(
* name="id",
* in="query",
* description="Buscar por estado",
* required=true,
* ),
查询指“查询字符串”,URL.
中?
之后的ampersand-separatedkey/value对集合