Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在swagger php api注释中传递可选参数?_Php_Swagger_Swagger Ui_Swagger 2.0_Swagger Php - Fatal编程技术网

如何在swagger php 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可选参数,而是接受必需

我使用的是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可选参数,而是接受必需的参数,请帮助我

要定义可选参数,只需不将其定义为非必需参数即可

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")