Problem with swagger array of objects: validation error: None is not of type 'array'

Problem with swagger array of objects: validation error: None is not of type 'array'

我正在尝试使 REST API 具有连接,但不知道如何设置使用对象数组的获取操作。最后,我需要一次获取有关多个项目的信息。

使用 Python 3.7、connexion-2.3.0 和 Swagger with OpenAPI 规范版本。 2.

我的 swagger 文件:

swagger: "2.0"
info:
  description: "This is documentation for REST api test."
  version: "1.0.0"
  title: test

consumes:
  - application/json
produces:
  - application/json

basePath: /api

paths:
  /test:
    get:
      operationId: test.test
      summary: "Just testing array."

      parameters:
        - name: query
          in: body
          schema:
            type: array
            items:
              $ref: '#/definitions/query'

      responses:
        200:
          description: All ok!

definitions:
  query:
      type: object

      required:
        - a
        - b

      properties:
        a:
          type: integer
          description: "Test propertie 1."
          example: 42

        b:
          type: string
          description: "Test propertie 2."
          example: "hi"

        c:
          type: string
          description: "Test propertie 3."
          example: "abc"

我的Python文件有测试功能:

def test(query):
    for item in query:
        print(item)

    return {'result': 'it is fine'}

试图通过 Swagger JSON UI:

[
  {
    "a": 42,
    "b": "hi",
    "c": "abc"
  }
]

我的测试函数的预期响应:

{
  "result": "it is fine"
}

实际回复:

{
  "detail": "None is not of type 'array'",
  "status": 400,
  "title": "Bad Request",
  "type": "about:blank"
}

问题是GET动词,不能用body。你应该使用类似的东西:

      parameters:
        - name: objects
          in: query
          required: true
          type: array
          items:
            type: string

数组元素的类型必须为:字符串、数字、整数、布尔值或数组