我可以让 swagger-php 在查询字符串上使用数组吗? [英] Can I make swagger-php use arrays on the query string?
问题描述
我使用 Swagger-php.当我在查询字符串上定义一个参数时,它可以是一个数组.但据我所知,它不支持这种查询字符串:
I use Swagger-php. When I define a parameter that's on the query string it can be an array. But from what I can see, it doesn't support this kind of querystring:
https://api.domain.tld/v1/objects?q[]=1&q[]=5&q[]=12
如果可能的话,我相信这会在collectionFormat
字段中设置.目前我一直在使用 pipes
,但我想使用上述格式,并且 Swagger-UI 也反映了这一点.但是,我阅读了 this github issue 这让我想知道这是否真的可能我刚刚错过了吗?
I believe this would be set in the collectionFormat
field if possible. Currently I've just been using pipes
, but I want to use the above format, and have Swagger-UI reflect this, too. However, I read this github issue which has left me wondering if this is actually possible and I've just missed it?
我的 Swagger-PHP 定义示例:
An example of my Swagger-PHP definition:
/**
* @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"
}
}
推荐答案
现在无需 [] hack 最喜欢的答案即可执行此操作.使用 deepObject 样式.
Its now possible to do this without [] hack of most liked answer. Use the deepObject style.
name: q
style: deepObject
schema:
type: array
items:
type: string
这将生成一个如下所示的网址:q[0]=string1&q[1]=string2
This will generate an url like following: q[0]=string1&q[1]=string2
这篇关于我可以让 swagger-php 在查询字符串上使用数组吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!