首页 > 解决方案 > (Swagger 2.0/ Connexion)无类型不是“字符串”类型

问题描述

我正在尝试通过 python connexion 创建一个简单的 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 中有没有让属性可以为空?网上找不到太多资料。谢谢!

标签: pythonflaskopenapiconnexion

解决方案


我认为你应该记下 type: string nullable: true

从这里我获得了信息 这个链接

它会是这样的:

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

推荐阅读