(Swagger 2.0/Connexion)None 类型不是 'string' 类型

(Swagger 2.0/ Connexion) None type is not of type 'string'

我正在尝试通过 python 连接创建一个简单的 post API。这是我的 api yaml 文件:

swagger: "2.0"

info:
  title: "My first API"
  version: "1.0"

basePath: /v1.0

paths:
  /potential:
    post:
      operationId: api.data.create_potential_data
      summary: Create the potential data
      parameters:
        - name: alertCategory
          in: body
          required: True
          description: The potential API request AlertCategoryDto object with settings of alert category (categorySystemName, alert Kpis etc.)
          schema:
            $ref: "#/definitions/alert"
      responses:
        201:
          description: Successfully created potential data


definitions:
  alert:
    properties:
      systemName:
        type: string
      name:
        type: string
      moduleSystemName:
        type: string

但是对于属性之一 name 我们 允许用户输入 null 值。 如果他们真的这样做了,我们将得到 error: None type is not of type 'string'

那么 swagger 2.0 中有没有使属性可以为空的?网上查不到太多资料。谢谢!

我觉得你应该写下 type: string 可为空:真

从这里我得到了信息 This link

会是这样的:

definitions:
  alert:
    properties:
      systemName:
        type: string
      name:
        type: string
        nullable: true
      moduleSystemName:
        type: string

感谢@Danilo 的帮助,我在这里从 connexion 的文档中找到了答案:

总之,添加x-nullable = true即可解决此问题。