我使用Swagger来编写Laravel API的文档,有时除了POSTMAN之外还有测试,问题是带参数的GET方法不能工作Route::get('/searchProduct/{id}','ApiReportController@getProductsByID');
但是,如果GET方法没有参数,它可以完美地工作。在Swagger中,我意识到当我进行查询时,我不会在{id}
中输入参数,但我相信在{id}?id=4
之后
这是我的路线
My route
Route::get('/searchProduct/{id}','ApiReportController@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,搜索对我有效。
这是我的控制器
/**
* @OAGet(
* path="/api/searchProduct/{id}",
* summary="Search Product by Status",
* description="Lorem ipsun",
* security={
* {"bearer_token":{}},
* },
* @OAParameter(
* name="id",
* in="query",
* description="Buscar por estado",
* required=true,
* ),
* @OAResponse(
* response=200,
* description="OK",
* @OAMediaType(
* mediaType="application/json",
* )
* ),
* @OAResponse(
* response="default",
* description="Ha ocurrido un error."
* ),
* @OAResponse(
* response="401",
* description="No se ha autenticado, ingrese el token."
* ),
* )
*/
public function getProductsByID($uuid){
$validated = Product::status($uuid);
return ReportResource::collection($validated);
}
尝试在此处用in="path",
替换in="query",
:
* @OAParameter(
* name="id",
* in="query",
* description="Buscar por estado",
* required=true,
* ),
查询是指";查询字符串";,URL中CCD_ 6之后的一组与符号分隔的键/值对。