我使用Swagger-php。当我在查询字符串上定义一个参数时,它可以是一个数组。但据我所见,它不支持这种查询:
https://api.domain.tld/v1/objects?q[]=1&q[]=5&q[]=12如果可能的话,我相信这将被设置为字段。目前我一直在使用pipes,但我想使用上述格式,而且Swagger也反映了这一点。然而,我读到了这个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"
}
}发布于 2019-11-25 15:06:10
现在,在不破坏最受欢迎的答案的情况下,这样做是可能的。使用deepObject样式。
name: q
style: deepObject
schema:
type: array
items:
type: string这将生成一个url,如下所示: q=string1&q1=string2
发布于 2017-04-18 07:09:40
/**
* @SWG\Parameter(
* name="q[]",
* in="query",
* description="A list of IDs (separated by new lines) to filter the Returns",
* required=false,
* type="array",
* collectionFormat="multi",
* uniqueItems=true,
* )
*/这将导致类似于此的结果
{
"name": "q[]",
"in": "query",
"description": "type",
"required": false,
"type": "array",
"collectionFormat": "multi",
"uniqueItems": true
}

发布于 2019-07-15 09:42:42
如果您还没有,我建议您尝试以下几种方法:
* @OA\Parameter(
* name="category[]",
* description="array of category numbers",
* in="query",
* @OA\Schema(
* type="array",
* @OA\Items(type="enum", enum={1,2,3,4,5,6,7,8,9}),
* example={1,2}
* )
* ),我修改了这个以适应我的用例:
* @OA\Parameter(
* name="things[]",
* in="query",
* description="A list of things.",
* required=false,
* @OA\Schema(
* type="array",
* @OA\Items(type="integer")
* )
* ),来源:https://github.com/zircote/swagger-php/issues/612#issue-380202012
https://stackoverflow.com/questions/37878018
复制相似问题