查询参数阵列中的数字索引是否在Swagger 2.0中表示?
我了解如何用Swagger 2.0表示查询参数中的数组:
?list=x&list=y
是否可以使用索引样式在Swagger 2.0中表示数组?
?list[0]=x&list[1]=y
I understand how to represent the array in query parameters with Swagger 2.0:
?list=x&list=y
Is it possible to represent an array in Swagger 2.0 using an indexed style?
?list[0]=x&list[1]=y
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OpenAPI 2.0(FKA Swagger 2.0)
list [0]
,list [1]
,list> list [2]
... ...list [list [list] [ n]
必须定义为单独的查询参数。无法将list
定义为单个数组类型参数,并以您想要的方式序列化。请注意,此方法仅适用于提前已知最大尺寸的固定尺寸阵列。
OpenAPI 3.0
一种方法是定义
list [0]
,list [1]
等作为单独的查询参数(例如,在OpenAPI 2.0示例中)。此方法适用于预先已知最大尺寸的固定尺寸阵列。另一种适用于未知大小数组的方法是使用 free -form查询参数。这种方法的限制在于,它允许任意参数名称 - 不仅是
list [n]
,还abcde
。但是,您可以提供描述
解释参数名称必须以格式list [n]
,并且提供示例>示例
值值文档目的。在Swagger UI中,在JSON对象(非数组)格式中输入查询参数,例如:
Swagger UI会将其转换为以下查询字符串(在URL编码之前):
OpenAPI 3.1
OAS 3.1将我们向前迈进了一步。您仍然会使用 free-form查询方法,但使用新的
pattern> pattern> pattern> pattern properties
关键字,以指定一个针对正则表达式的关键字允许的参数名称(例如^list \ [\ d+\] $
)。OpenAPI 2.0 (fka Swagger 2.0)
list[0]
,list[1]
,list[2]
...list[N]
must be defined as separate query parameters. There's no way to definelist
as a single array-type parameter and have it serialized the way you want.Note that this approach only works for fixed-sized arrays whose maximum size is known in advance.
OpenAPI 3.0
One approach is to define
list[0]
,list[1]
, etc. as separate query parameters (like in the OpenAPI 2.0 example above). This approach is suitable for fixed-sized arrays whose maximum size is known in advance.Another approach - suitable for arrays of unknown size - is to define such an array using free-form query parameters. The limitation of this approach is that it allows arbitrary parameter names - not just
list[n]
but alsoabcde
. However, you can provide adescription
explaining that the parameter names must be in the formatlist[n]
, and also provide anexample
value for documentation purposes.In Swagger UI, enter the query parameters in the JSON object (not array) format, like so:
Swagger UI will convert this into the following query string (before URL encoding):
OpenAPI 3.1
OAS 3.1 takes us one step forward. You would still use the free-form query approach but narrow it down by using the new
patternProperties
keyword to specify a regular expression for the allowed parameter names (e.g.^list\[\d+\]$
).