当前位置: 首页 > 知识库问答 >
问题:

招摇的对象数组出现问题:验证错误:无不是“数组”类型。

孔厉刚
2023-03-14

我试图使REST API与Connexion,但无法弄清楚如何设置获取操作消耗对象数组。最后,我需要一次获取有关多个项目的信息。

使用 Python 3.7、connexion-2.3.0 和 Swagger with OpenAPI Specification ver. 2。

我的招摇文件:

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 UI传递JSON:

[
  {
    "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"
}

共有1个答案

陆承宣
2023-03-14

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

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

数组项目必须是类型:字符串、数字、整数、布尔值或数组

 类似资料:
  • 本文向大家介绍PHP 验证数组类型,包括了PHP 验证数组类型的使用技巧和注意事项,需要的朋友参考一下 示例 is_array()如果变量是数组,则函数返回true。 您可以在函数中键入提示数组类型以强制执行参数类型。传递其他任何内容都会导致致命错误。 您也可以使用该gettype()功能。            

  • 本文向大家介绍jQuery Validate 数组 全部验证问题,包括了jQuery Validate 数组 全部验证问题的使用技巧和注意事项,需要的朋友参考一下 jquery validate撇开效率不说,功能上比较全,扩展比较简单,比较好用。但是也不能涵盖所有。下面举例说明 html中有多个name[],每个参数都要进行验证是否为空,这个时候直接用required:true话,不能全部验证,只

  • 我使用的是OpenApi规范,这是生成类的代码示例: 我想禁止发送以下请求: 如果我使用了它看起来像: 有什么方法可以使用文件做同样的事情吗?

  • 我今天才开始使用翻新图书馆。我在获取一些json数据时遇到问题。 我试图获取的JSON数据如下所示: 求求你,救命!

  • 问题内容: 我收到错误消息: 第183行上的“致命错误:无法将stdClass类型的对象用作数组” 从此代码: 有人知道上面的代码有什么问题吗?还是这个错误是什么意思? 问题答案: CodeIgniter将结果行作为对象而不是数组返回。从用户指南中: 结果() 此函数以 对象 数组或失败时 为空数组的形式 返回查询结果。 您必须使用以下符号访问字段:

  • 我有一个数组对象作为道具传递数组看起来像: 我想做的是添加propTypes验证,比如 标题:道具类型。一串需要 sub_items:PropTypes.array sub_items:数组内的道具验证,如标题刺痛和isDriningboolean。 请注意如何在阵列上实现这一点。(注:我的知识非常有限,所以如果我问了一个明显愚蠢的问题,请原谅)