我使用 Swagger-php。当我在查询字符串上定义一个参数时,它可以是一个数组。但据我所知,它不支持这种查询字符串:
https://api.domain.tld/v1/objects?q[]=1&q[]=5&q[]=12
如果可能的话,我相信这将在collectionFormat
现场设置。目前我一直在使用pipes
,但我想使用上述格式,并让 Swagger-UI 也反映这一点。但是,我阅读了这个 github 问题,这让我想知道这是否真的可行,而我只是错过了它?
我的 Swagger-PHP 定义示例:
/**
* @SWG\Parameter(
* name="ids",
* in="query",
* description="A list of IDs (separated by pipes) to filter the Returns",
* required=false,
* type="array",
* @SWG\Items(
* type="integer",
* format="int32"
* ),
* collectionFormat="pipes"
* )
*/
这会产生以下 JSON:
"parameters": {
"ids": {
"name": "ids",
"in": "query",
"description": "A list of IDs (separated by pipes) to filter the Returns",
"required": false,
"type": "array",
"items": {
"type": "integer",
"format": "int32"
},
"collectionFormat": "pipes"
}
}