Swagger OpenAPI3-如何描述一个整数数组但可以是单个项的查询参数?

Swagger OpenAPI3-如何描述一个整数数组但可以是单个项的查询参数?,swagger,jsonschema,openapi,ajv,Swagger,Jsonschema,Openapi,Ajv,使用OpenAPI3.0.1,我试图描述一个类型为“integer”的查询参数,比如我们称它为ids,它可以是单独的,也可以是数组 例如: /my endpoint?ids=111 或 /my endpoint?ids=111&ids=222 我确实试过: - name: ids in: query required: false schema: type: array items: type: integer 我知道style:form和explode

使用OpenAPI3.0.1,我试图描述一个类型为“integer”的查询参数,比如我们称它为
ids
,它可以是单独的,也可以是数组

例如:

/my endpoint?ids=111

/my endpoint?ids=111&ids=222

我确实试过:

- name: ids
  in: query
  required: false
  schema:
    type: array
    items:
      type: integer
我知道
style:form
explode:true

但是,当我用实际请求验证这一点时(我使用的是一个包装器),我会得到这些错误:

/我的端点?ids=111

/我的端点?ids=111&ids=222&ids=333

如果我使用“字符串”而不是“整数”:

/我的端点?ids=111

/我的端点?ids=111&ids=222&ids=333

我应该如何描述这个
ids
参数,它必须是整数值


更新:我现在了解到,当Express服务器(我使用)反序列化时,任何查询参数都将是一个
字符串。但我仍然无法使用单个元素数组

在@Helen的评论之后,我尝试了另一个验证库,现在它可以很好地用于:

- name: ids
  in: query
  required: false
  style: form
  explode: true
  schema:
    type: array
    items:
      type: integer
有了,我唯一能让它工作的方法就是使用:

- name: ids
  in: query
  required: false
  schema:
    anyOf:
      - type: array
        items:
          type: string
          pattern: '^\d+$'
      - type: string  
        pattern: '^\d+$'

因此,我建议您使用Express server。

您的原始示例(仅包含一个整数数组)实际上是您用例的正确定义。验证错误可能是您使用的验证库或服务器端框架中的错误。很高兴知道,谢谢@Helen
- name: ids
  in: query
  required: false
  schema:
    type: array
    items:
      type: string
"Error while validating request: request.query.ids should be array"
Valid!
- name: ids
  in: query
  required: false
  style: form
  explode: true
  schema:
    type: array
    items:
      type: integer
- name: ids
  in: query
  required: false
  schema:
    anyOf:
      - type: array
        items:
          type: string
          pattern: '^\d+$'
      - type: string  
        pattern: '^\d+$'