如何在swagger php api注释中传递可选参数?
我使用的是swagger ui,我有一个Get api,它是可选的 参数,但我无法为下面的api提供注释 制作我尝试过的代码: 我的Get api结构如下所示:如何在swagger php api注释中传递可选参数?,php,swagger,swagger-ui,swagger-2.0,swagger-php,Php,Swagger,Swagger Ui,Swagger 2.0,Swagger Php,我使用的是swagger ui,我有一个Get api,它是可选的 参数,但我无法为下面的api提供注释 制作我尝试过的代码: 我的Get api结构如下所示: $app->get('/checkDataNameAvailability/:type/:name(/:id)', function($type, $name, $id = '') use($app){ //here is my api code }); 但是,当我尝试这样做时,大摇大摆的用户界面不接受id可选参数,而是接受必需
$app->get('/checkDataNameAvailability/:type/:name(/:id)', function($type, $name, $id = '') use($app){
//here is my api code
});
但是,当我尝试这样做时,大摇大摆的用户界面不接受id可选参数,而是接受必需的参数,请帮助我 要定义可选参数,只需不将其定义为非必需参数即可
id
参数具有required=true
:
@SWG\Parameter(name="id",in="path",description="optional, useful data by id",required=true,type="integer", @SWG\Items(type="integer"),collectionFormat="csv",format="int32")
您只需将其设置为false:
@SWG\Parameter(name="id",in="path",description="optional, useful data by id",required=false,type="integer", @SWG\Items(type="integer"),collectionFormat="csv",format="int32")
删除required=true
也使此参数成为可选参数
@SWG\Parameter(name="id",in="path",description="optional, useful data by id",type="integer", @SWG\Items(type="integer"),collectionFormat="csv",format="int32")
@SWG\Parameter(name="id",in="path",description="optional, useful data by id",type="integer", @SWG\Items(type="integer"),collectionFormat="csv",format="int32")