Leo*_*lis 4 php swagger swagger-php swagger-ui
我用Swagger-php.当我定义查询字符串上的参数时,它可以是一个数组.但从我所看到的,它不支持这种查询字符串:
https://api.domain.tld/v1/objects?q[]=1&q[]=5&q[]=12
Run Code Online (Sandbox Code Playgroud)
我相信如果可能的话,这将在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"
* )
*/
Run Code Online (Sandbox Code Playgroud)
这导致以下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"
}
}
Run Code Online (Sandbox Code Playgroud)
/**
* @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,
* )
*/
Run Code Online (Sandbox Code Playgroud)
这将产生类似于此的东西
{
"name": "q[]",
"in": "query",
"description": "type",
"required": false,
"type": "array",
"collectionFormat": "multi",
"uniqueItems": true
}
Run Code Online (Sandbox Code Playgroud)
现在无需 [] hack 最喜欢的答案就可以做到这一点。使用 deepObject 样式。
name: q
style: deepObject
schema:
type: array
items:
type: string
Run Code Online (Sandbox Code Playgroud)
这将生成如下所示的 url:q[0]=string1&q[1]=string2
| 归档时间: |
|
| 查看次数: |
3432 次 |
| 最近记录: |