问题描述
我正在使用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中?
之后的与号分隔的键/值对的集合。