带有对象列表的 OpenAPI 查询字符串参数 [英] OpenAPI query string parameter with list of objects

查看:40
本文介绍了带有对象列表的 OpenAPI 查询字符串参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 OpenAPI 记录一个看起来像

I am trying to document with OpenAPI a query string which look like

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

并包含具有 idvalue 属性的对象列表.

and contains a list of object with properties id and value.

我的 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 选项仅适用于一个级别,而不适用于我的对象实际所在的第二个级别.也就是说,它需要一个查询字符串,如

The problem is the following: it looks like the style: deepObject option works only for one level, and not at the second level where my objects actually are. That is, it expects a query string like

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

对象未序列化为具有 idvalue 键的数组.

with the object not serialized as an array with id and value keys.

有没有办法解决这个问题?

Is there a way to solve this?

推荐答案

这在 OpenAPI 3.1 中是不可能的

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

OpenAPI 3.0/3.1 Specifications currently defines the deepObject behavior only for simple objects (with primitive properties) such as

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

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

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

Since the behavior for arrays and nested objects is not defined, there's really no way to describe your query string. Technically, the only way would be to define filtered[0][id], filtered[0][value], etc. as individual query parameters.

这篇关于带有对象列表的 OpenAPI 查询字符串参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆