带有对象列表的 OpenAPI 查询字符串参数

2023-12-14

我正在尝试记录OpenAPI一个查询字符串,看起来像

filtered[0][id]=code&filtered[0][value]=12345

并包含具有属性的对象列表id and value.

My yaml文档如下所示

parameters:
    - name: filtered
      in: query
      description: filters to be applied
      explode: true
      style: deepObject
      schema:
        type: array
        items:
          properties:
            id:
              description: name of the field to be filtered
              type: string
            value:
              description: value of the filter
          type: object

问题如下:看起来像style: deepObject选项仅适用于一级,不适用于我的对象实际所在的第二级。也就是说,它需要一个像这样的查询字符串

?sorted[0]=%7B%0A%20%20%22id%22%3A%20%22string%22%2C%0A%20%20%22value%22%3A%20true%0A%7D

对象未序列化为数组id and value keys.

有办法解决这个问题吗?


从 OpenAPI 3.1 开始这是不可能的

OpenAPI 3.0/3.1 规范当前定义了deepObject行为仅适用于简单物体(具有原始属性)例如

{
  "id": 5,
  "name": "Bob"
}

but 不适用于数组 and 不适用于嵌套对象.

由于未定义数组和嵌套对象的行为,因此实际上无法描述您的查询字符串。从技术上讲,唯一的方法是定义filtered[0][id], filtered[0][value]等作为单独的查询参数。


If you are designing a new API (rather than describing an existing one), consider passing the array of objects in the request body instead.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

带有对象列表的 OpenAPI 查询字符串参数 的相关文章

随机推荐