我正在使用招摇的 UI,我有一个获取 api,它采取可选的 参数,但我无法为下面的 API 提供注释 制作我尝试过的代码:
/**
* @SWGGet(
* path="/basics/checkDataNameAvailability/{type}/{name}{/id}",
* tags={"Emergency"},
* description="Return data useful for userGroup, deviceGroups and deviceTags",
* produces={"application/json", "application/xml", "text/xml", "text/html"},
* @SWGParameter(name="type",in="path",description="return useful data by type",required=true,type="integer", @SWGItems(type="integer"),collectionFormat="csv",format="int32"),
* @SWGParameter(name="name",in="path",description="return useful data by name",required=true,type="integer", @SWGItems(type="integer"),collectionFormat="csv",format="int32"),
* @SWGParameter(name="id",in="path",description="optional, useful data by id",required=true,type="integer", @SWGItems(type="integer"),collectionFormat="csv",format="int32"),
* @SWGResponse(response=200,description="Dashboard Response",
* @SWGSchema(type="array",@SWGItems(ref="#/definitions/Pet"))
* ),
* @SWGResponse(response="default",description="unexpected error",
* @SWGSchema(ref="#/definitions/ErrorModel")
* ),
* @SWGExternalDocumentation(description="find more info here", url="https://swagger.io/about")
* )
*/
我的获取 api 结构是这样的:
$app->get('/checkDataNameAvailability/:type/:name(/:id)', function($type, $name, $id = '') use($app){
//here is my api code
});
但是当我尝试这个时,大摇大摆的 ui 不采用 id 可选参数,它采用必需参数,帮助我。.
要定义可选参数,只需不要将其定义为"非必需"。
id
参数具有required=true
:
@SWGParameter(name="id",in="path",description="optional, useful data by id",required=true,type="integer", @SWGItems(type="integer"),collectionFormat="csv",format="int32")
你只需要把它设置为 false:
@SWGParameter(name="id",in="path",description="optional, useful data by id",required=false,type="integer", @SWGItems(type="integer"),collectionFormat="csv",format="int32")
删除required=true
也会使此参数成为可选参数
@SWGParameter(name="id",in="path",description="optional, useful data by id",type="integer", @SWGItems(type="integer"),collectionFormat="csv",format="int32")